gpt4 book ai didi

c# - View MVC C# 中的格式异常

转载 作者:太空宇宙 更新时间:2023-11-03 23:37:03 25 4
gpt4 key购买 nike

以下是摘 self 的 View 模型的片段:

[Display(Name = "Time")]
[Required(ErrorMessage = "Is required field. Format hh:mm (24 hour time)")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:HH:mm}")]
public Nullable<System.TimeSpan> EventPerformance_Time { get; set; }

这是来 self 的 View.cshtml:

<div class="form-group">
@Html.LabelFor(model => model.EventPerformance_Time, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EventPerformance_Time, "{0:HH:mm}", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EventPerformance_Time, "", new { @class = "text-danger" })
</div>
</div>

当我运行项目时,我不断收到以下错误:

FormatException: Input string was not in a correct format.

@Html.EditorFor.....等行

我尝试了很多不同的“解决方案”,但没有一个奏效,我很困惑到底出了什么问题,因为在另一个 View 模型中它工作得很好!

有什么帮助吗?非常感激。

最佳答案

我很想看看您的示例在哪里起作用。您使用的是什么版本的 MVC?在EditExtension.EditorForEditorExtensions.EditorFor Methods文档我没有看到支持你正在做的事情的方法签名。你能不能按照这些思路做点什么Html.TextBoxFor formatting or Html.EditorFor htmlAttributes?

关于c# - View MVC C# 中的格式异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30278039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com