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; }
View:
<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")
}
Controller:
public ActionResult Create()
{
ViewBag.BusinessGroups = DB.BusinessGroups.Where(x => x.is_active).OrderBy(x => x.value).ToList();
return View();
}
Web.config:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…