ListBoxFor客户端验证ASP.net MVC

时间:2014-05-14 14:40:37

标签: c# asp.net asp.net-mvc

这是我的模特:

public partial class TAUX
    {
        ....
        [Required(ErrorMessage="Select one At least")]
        public IEnumerable<short> SelectItems { set; get; }
    }

这是我的观点:

@model pfebs0.Models.TAUX
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="/Scripts/chosen.jquery.js" type="text/javascript"></script>
<link href="/Content/chosen.css" rel="stylesheet"  type="text/css" />
...
            $(".chosen-select").chosen({ width: "100%"})
</script> 
...
            @Html.ListBoxFor(model => model.SelectItems, (ViewBag.CAT_ID as SelectList), new { @class = "chosen-select", data_placeholder = "Selection une Categorie..." })
            @Html.ValidationMessageFor(model => model.SelectItems)

客户端验证在我的ListBox中不起作用,但对于其他属性,它可以正常工作。如何解决?

1 个答案:

答案 0 :(得分:0)

@Html.ValidationMessageFor(model => model.CAT_ID)

更改为

@Html.ValidationMessageFor(model => model.SelectItems)