jQuery的下拉选上验证客户端站点无法正常工作 [英] jQuery Chosen Dropdown validation client site doesn't work
本文介绍了jQuery的下拉选上验证客户端站点无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的模型类包含所需的查找值,它是一个基于查找记录的:
My model class contains of required lookup value which is a lookup-based record:
[Required]
[DisplayName("Business Unit")]
public string value { get; set; }
[Required] //not working on client side?
[DisplayName("Business Group")]
public int id_businessgroup { get; set; }
查看:
<div class="editor-label">
@Html.LabelFor(model => model.value)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.value)
@Html.ValidationMessageFor(model => model.value)
</div>
<div class="editor-label">
@Html.LabelFor(x=>x.BusinessGroup.value)
</div>
<div class="editor-field">
@Html.DropDownListFor(x => x.id_businessgroup, new SelectList(ViewBag.BusinessGroups,"id","value"),"Please select group from list...")
@Html.ValidationMessageFor(x => x.id_businessgroup)
</div>
@section scripts{
@Html.Partial("ScriptUseChosen")
}
控制器:
public ActionResult Create()
{
ViewBag.BusinessGroups = DB.BusinessGroups.Where(x => x.is_active).OrderBy(x => x.value).ToList();
return View();
}
Web.config文件:
Web.config:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
BundleConfig.cs:
BundleConfig.cs:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*",
"~/Scripts/jquery.unobtrusive*"));
为值
验证是在客户端完美的工作,但它不工作所选择的下拉列表。可能是什么原因呢?
Validation for value
is working perfectly on client side, but it's not working on the Chosen's dropdown. What could be the reason?
推荐答案
jQuery的获选通过更新HTML原来选择隐藏(风格=显示:无
) 。默认情况下jquery.validate(1.9.0)忽略隐藏的元素。您可以使用覆盖默认
jQuery Chosen updates the html by making the original select hidden (style="Display:none"
). By default jquery.validate (1.9.0) ignores hidden elements. You can override the default using
$.validator.setDefaults({
ignore: []
});
或
$('form').validate({
ignore: []
});
这篇关于jQuery的下拉选上验证客户端站点无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文