由于无法使用,我在尝试验证时遇到问题
<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; }
}