ASP .NET Core验证复选框集合客户端

时间:2019-07-13 11:41:16

标签: javascript asp.net-core

由于无法使用,我在尝试验证时遇到问题

<span asp-validation-for="" class="text-danger"></span>

这是我在表单中更新的代码。没有客户端验证

<form id="form" method="post">
<div class="form-row">
    <div class="form-group col-md-12">
        <ul class="list-group">
            @for (var i = 0; i < Model.CodeRequestsViewModelList.Count; i++)
            {
                <li class="list-group-item">
                    <div class="custom-control custom-checkbox">
                         <input type="checkbox" asp-for="@Model.CodeRequestsViewModelList[i].Selected" class="custom-control-input" />
                         <label asp-for="@Model.CodeRequestsViewModelList[i].Selected" class="custom-control-label">@Model.CodeRequestsViewModelList[i].Nome</label>
                         <input type="hidden" asp-for="@Model.CodeRequestsViewModelList[i].Id" />
                         <input type="hidden" asp-for="@Model.CodeRequestsViewModelList[i].Nome" />
                    </div>
                </li>
            }
        </ul>
    </div>
</div>
<button class="btn btn-primary" type="submit">Submit</button>
</form>

@section Scripts{
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

}

代码已更新

具有属性和视图模型列表的页面模型

 [BindProperty]
 public IList<CodeRequestViewModel> CodeRequestsViewModelList { get; set; }


    public class CodeRequestViewModel
    {
        public int Id { get; set; }
        public string Nome { get; set; }
        public bool Selected { get; set; }
    }

0 个答案:

没有答案