当我在MVC Razor视图中使用Kendo UI组合框和DropDownList控件时,客户端验证不会触发。这里有一个例子:如何为Kendo UI DropDownList和ComboBox启用ASP.Net MVC客户端验证?
@using Kendo.Mvc.UI
@model KendoDropDownTest.Models.TestModel
@{
ViewBag.Title = "Kendo Drop Down and Combo Box Test";
}
<h2>Kendo Drop Down and Combo Box Test</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary()
<div>
@Html.LabelFor(x => x.DropDownValue)
@(Html.DropDownListFor(x => x.DropDownValue, Model.Options, "-- Select an Option --"))
@Html.ValidationMessageFor(x => x.DropDownValue)
</div>
<fieldset>
<legend>Kendo</legend>
<div>
@Html.LabelFor(x => x.KendoComboValue)
@(Html.Kendo().ComboBoxFor(x => x.KendoComboValue)
.BindTo(Model.Options.Select(x => x.Text)))
@Html.ValidationMessageFor(x => x.KendoComboValue)
</div>
<div>
@Html.LabelFor(x => x.KendoDropDownValue)
@(Html.Kendo().DropDownListFor(x => x.KendoDropDownValue)
.OptionLabel("-- Select an Option --")
.BindTo(Model.Options))
@Html.ValidationMessageFor(x => x.KendoDropDownValue)
</div>
</fieldset>
<input type="submit" value="Submit" />
}
,对应的模式:
public class TestModel
{
[Required]
public string DropDownValue { get; set; }
[Required]
public string KendoComboValue { get; set; }
[Required]
public string KendoDropDownValue { get; set; }
public SelectListItem[] Options = new[]
{
new SelectListItem
{
Text = "Option 1",
Value = "1"
},
new SelectListItem
{
Text = "Option 2",
Value = "2"
},
new SelectListItem
{
Text = "Option 3",
Value = "3"
},
};
}
非剑道UI下拉适当显示验证错误时提交表单,但剑道控件不。请让我知道是否有办法为这些控件启用客户端验证,而无需手动连线。
完整的例子液附着于以下剑道论坛上发帖: http://www.kendoui.com/forums/mvc/dropdownlist/mvc-client-validation-not-working.aspx
对于jQuery验证1.9,你必须[组'ignore'为空数组(http://stackoverflow.com/a/8565769/26226)。 – jrummell
发现了一个很好的补充。如果您有其他控件,如果隐藏时不想验证其他控件,但希望隐藏特定控件,则可以将它们添加到不(忽略)以展开此有用提示:例如,我们将.kendoDD标记在Kendo Dropdown上,然后设置: $ .validator.setDefaults({0:隐藏:不((.kendoDD)“ }); https://stackoverflow.com/questions/20287567/ignore-all-hidden-div-but-not-one-in-jquery-validation – Mike