【发布时间】:2015-02-19 09:31:52
【问题描述】:
我正在处理一个 ASP.NET MVC 4 项目,但在为整数字段显示正确的验证标签时遇到了问题。
这是我的模型属性:
[Required(ErrorMessage = "Please enter the title.")]
public string Title { get; set; }
[Required(ErrorMessage = "Please select a country.")]
public int RegionId { get; set; }
这是我的cshtml:
@Html.TextBoxFor(m => m.article.Title, new { @placeholder = "Title", @autofocus = true })
@Html.ValidationMessageFor(m => m.article.Title)
@(Html.Kendo().DropDownList()
.Name("RegionControl")
.DataTextField("Name")
.DataValueField("RegionId")
.OptionLabel("Select one...")
.Events(e => e.Change("RegionChange").DataBound("RegionDataBound"))
.BindTo(Model.regions)
.Value(Model.article.RegionId.ToString())
@Html.ValidationMessageFor(m => m.article.RegionId)
我的问题是标题的验证消息显示正常 ("Please enter the title."),但下拉列表的验证是默认的 ("The value 'NaN' is not valid for RegionId.")。
为什么RegionId的验证消息没有显示我在模型("Please select a country.")中设置的消息?是不是因为默认值(OptionLabel)?我该如何解决?
【问题讨论】:
-
这个问题需要去掉
html.dropdownlistfor标签并添加Kendo标签 -
为什么你还有一个隐藏的属性输入?
-
是的,抱歉你是对的@StephenMuecke,你可以忽略 hiddenfor。 (答案已编辑)
-
@markpsmith,绝对感谢您的编辑!
-
没人知道这个话题吗?
标签: c# asp.net asp.net-mvc kendo-ui