jQuery验证和最小长度的集合

时间:2018-01-10 05:13:20

标签: javascript c# jquery asp.net-mvc unobtrusive-validation

我有一个属性

    [MinLength(1, ErrorMessage = "Must map at least 1 component.")]
    [Required]
    public Thingy[] Thingys { get; set; }

呈现给视图,如

         @Html.ValidationMessageFor(model => model.Thingys, string.Empty, new { @class = "text-danger" })
        <tbody>

            @for (int i = 0; i < Model.Thingys.Length; ++i)
            {
                <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>
                        @(Model.Thingys[i].State)
                        @Html.Hidden("Thingys[" + @i + "].State", Model.Thingys[i].State, new { @class= "form-control thingy-state" })
                    </td>
                    <td>
                        @(Model.Thingys[i].Id)
                        @Html.Hidden("Thingys[" + @i + "].Id", Model.Thingys[i].Id, new { @class = "form-control thingy-id" })
                    </td>
                    <td>
                        @(Model.Thingys[i].Name)
                        @Html.Hidden("Thingys[" + @i + "].Name", Thingys.Components[i].Name, new { @class = "form-control thingy-name" })
                    </td>
                </tr>
            }
        </tbody>

如果没有行,我希望它能被jQuery验证。知道我错过了什么吗?

0 个答案:

没有答案