问题
In my view I have a kendo dropdownlist. I´ve implement jQuery validation inserting these scripts in the view:
<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>
I've set the property as Required in the entity and all I need to perform the validation.
Model:
[Required(ErrorMessage = "Campo Tipo de Llenado es necesario")]
public int TipoLlenado { get; set; }
View:
@(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)
The thing is that if I inspect the web with Chrome and remove the "display:none" style from the input generated by the kendo DropDownList (using Razor), and then press the Submit button the validation works fine.
I've tried the following solutions without result:
$(document).ready(function () {
$('#formu').validate({
ignore: []
});
}
OR
$(document).ready(function () {
$('#formu').validate({
ignore: ':hidden'
});
}
OR
$.validator.setDefaults({ ignore: []});
OR
$.validator.setDefaults({ ignore: ':hidden' });
Any advise??
Thanks in advance!!
回答1:
I've found the mistake. It was that I have to write the line:
$.validator.setDefaults({
ignore: []
});
outside of $(document).ready(function () {...}
来源:https://stackoverflow.com/questions/22476862/jquery-validate-kendo-dropdownlist-with-displaynone-style