jQuery - 使用display:none style验证kendo下拉列表

时间:2014-03-18 10:39:44

标签: asp.net-mvc-4 kendo-ui jquery-validate html.dropdownlistfor

在我看来,我有一个剑道下拉列表。我实现了在视图中插入这些脚本的jQuery验证:

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

我已在实体中将属性设置为必需,并且我需要执行验证。

型号:

[Required(ErrorMessage = "Campo Tipo de Llenado es necesario")]
        public int TipoLlenado { get; set; }

查看:

@(Html.Kendo()
    .DropDownListFor(model => model.pedidoGranelAutoEs.TipoLlenado)
    .BindTo(new SelectList(cmbTipoLlenado.Select(s => new { Key = s.IdDatoMaestro, Value = s.ValorPortal }), "Key", "Value"))
    .Events(events =>
    {
        events.Select("selectTipoLlenado");                         
    })
    .OptionLabel(Idioma.Shared.Pedidos_SeleccioneOpcion)
    )
@Html.ValidationMessageFor(model => model.pedidoGranelAutoEs.TipoLlenado)

问题是,如果我使用Chrome检查网络并从kendo DropDownList(使用Razor)生成的输入中删除“display:none”样式,然后按“提交”按钮,则验证工作正常。

jQuery - validate kendo dropdownlist with display:none style

我尝试了以下解决方案但没有结果:

$(document).ready(function () {
        $('#formu').validate({
            ignore: []
        });
}

OR

$(document).ready(function () {
        $('#formu').validate({
            ignore: ':hidden'
        });
}

OR

$.validator.setDefaults({ ignore: []});

OR

$.validator.setDefaults({ ignore: ':hidden' });

任何建议??

提前致谢!!

1 个答案:

答案 0 :(得分:3)

我发现了这个错误。 我必须写下这句话:

$.validator.setDefaults({
        ignore: []
    });

$(document).ready(function () {...}之外