在此表单中使用了错误的验证摘要。
查看: -
<div class="col-md-12 table-bordered" style="padding: 20px; margin:10px;">
<div class="col-md-12">@Html.ValidationSummary(false,"Please Correct Following details :", new { @class = "text-danger" })</div>
<div class="col-md-12" style="padding:10px;">
<div class="col-md-6">
<div style="width:95%;">
@Html.LabelFor(Model => Model.ItemName, new { style = "font-weight:bold;", @maxlength = "100" })
@Html.TextBoxFor(Model => Model.ItemName)
<span class="text-danger"> @Html.ValidationMessageFor(Model => Model.ItemName) </span>
</div>
</div>
<div class="col-md-6">
<div style="width:75%;">
@Html.LabelFor(Model => Model.ActiveProductGroup, new { style = "font-weight:bold;" })
@Html.DropDownListFor(Model => Model.ProductGroupID, new SelectList(ViewBag.ActiveProductGroup, "Value", "Text"), "--Select Value--", new { style = "Width:95%" })
<span class="text-danger"> @Html.ValidationMessageFor(Model => Model.ActiveProductGroup) </span>
</div>
</div>
</div>
<div class="col-md-12" style="padding:10px;">
<div class="col-md-3">
<div style="width:70%;">
@Html.LabelFor(Model => Model.SequenceNumber, new { style = "font-weight:bold;" })
@Html.TextBoxFor(Model => Model.SequenceNumber, new { style = "text-align:right", @maxlength = "3" })
<span class="text-danger"> @Html.ValidationMessageFor(Model => Model.SequenceNumber) </span>
</div>
</div>
<div class="col-md-3">
<div style="width:50%;">
@Html.LabelFor(Model => Model.UnitPrice, new { style = "font-weight:bold;" })
@Html.TextBoxFor(Model => Model.UnitPrice, new { style = "text-align:right", @maxlength = "5" })
<span class="text-danger"> @Html.ValidationMessageFor(Model => Model.UnitPrice) </span>
</div>
</div>
<div class="col-md-3">
<div style="width:50%;">
@Html.LabelFor(Model => Model.Quantity, new { style = "font-weight:bold;" })
@Html.TextBoxFor(Model => Model.Quantity, new { style = "text-align:right", @maxlength = "5" })
<span class="text-danger"> @Html.ValidationMessageFor(Model => Model.Quantity) </span>
</div>
</div>
<div class="col-md-3">
<div style="width:80%;">
@Html.LabelFor(Model => Model.EstimatedDeliveryDays, new { style = "font-weight:bold;" })
@Html.TextBoxFor(Model => Model.EstimatedDeliveryDays, new { style = "text-align:right", @maxlength = "2" })
<span class="text-danger"> @Html.ValidationMessageFor(Model => Model.EstimatedDeliveryDays) </span>
</div>
</div>
</div>
</div>
在此使用的html.validation摘要中
在此表单中,它应在文本框下方显示星号(*)符号,并在验证摘要中显示错误
如何实现?
答案 0 :(得分:2)
您不能在模型中使用Required属性吗?
示例:
public class ClassName{
[Required(ErrorMessage = "* Please enter Item Name")]
public string ItemName {get;set;}
}