【发布时间】:2020-09-20 08:19:23
【问题描述】:
我在 foreach 下使用 asp-validation-for 并面临以下问题。假设使用 foreach 生成 3 个文本控件。我正在使用 [required] 模型注释。 “objGenExaminationTemplateChoicesModel”对象是主模型中的ICollection。
-
如果第一个文本控件为空,系统将显示错误消息 所有 3 个文本控件。
-
如果第二个或第三个是空系统不是 显示任何消息但由于型号原因不继续发布页面 错误。
<table id="dtChoices" class="table table-borderless table-striped"> <thead class="bg-primary"> <tr> <th class="text-left"><label asp-for="@Model.objGenExaminationTemplateChoicesModel.FirstOrDefault().ChoiseDescription" class="control-label"></label></th> <th style="width:30px"><a href="#" id="AddNewChoice" class="text-warning"><span class="sidenav-icon icon icon-plus-square pull-right" style="font-size:large"> </span></a></th> </tr> </thead> <tbody> @foreach (var objGenExaminationTemplateChoiceModel in Model.objGenExaminationTemplateChoicesModel) { iCounter = iCounter + 1; <tr> <td class="text-left form-group form-group-sm"> <input type="text" asp-for="@objGenExaminationTemplateChoiceModel.ChoiseDescription" class="form-control"> <span asp-validation-for="@objGenExaminationTemplateChoiceModel.ChoiseDescription" class="text-danger"></span> </td> <td> <a href="#" class="text-warning btnDeleteRow" data-toggle="modal" data-target="#deleteConfirmationModalAlert"> <span class="sidenav-icon icon icon-trash pull-right" style="font-size:large"> </span> </a> </td> </tr> } </tbody>
【问题讨论】:
-
我也尝试了以下代码行但不起作用。
标签: asp.net-core