在MVC 3中进行非干扰的下拉验证 [英] Unobtrusive dropdown validation in MVC 3
本文介绍了在MVC 3中进行非干扰的下拉验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,下面的链接概述了MVC 3的问题/具有下拉列表的不干扰验证.本质上,不会为下拉列表发出客户端验证脚本.有一个简单的解决方法吗?当在最终版本发布之前就已经报告了该错误时,我对MVC 3的发布方式感到困惑.我们等待修复时是否浮现出一个简单的解决方案?
So the link below outlines a problem with MVC 3 / unobtrusive validation with dropdown lists. Essentially client side validation script is not emitted for dropdown lists. Is there a straightforward workaround for this? I'm confused as to how MVC 3 was released like this when this bug was reported well before the final release. Is there a simple solution to this that's surfaced while we wait for a fix?
也许我很孤单,但是验证表单的所有元素似乎很重要. :)
Maybe I'm alone on this, but it seems validating ALL elements of a form is important. :)
推荐答案
对于我来说似乎也很好
<p>
<p>
<span class="lbl"> @Html.LabelFor(x => x.SelectedTimeZone, " Select a TimeZone: ")</span>
<span>@Html.DropDownListFor(x => x.SelectedTimeZone, Model.TimeZones)</span>
<span class="validation-error">@Html.ValidationMessageFor(x => x.SelectedTimeZone)</span>
</p>
//查看模型
[Required(ErrorMessage = "Time zone is required")]
public string SelectedTimeZone { get; set; }
public SelectList TimeZones { get; set; }
public SetupViewModel()
{
TimeZones = new SelectList(TimeZoneExtensions.BuildTimeZoneList(), "value", "text", "selected");
SelectedTimeZone = "UTC";
}
这篇关于在MVC 3中进行非干扰的下拉验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文