简体   繁体   English

如何在MVC中使用星号显示验证摘要?

[英]how to show validation summary with asterisk in mvc?

在此处输入图片说明

In this Form used validation summary for errors. 在此表单中,使用了针对错误的验证摘要。

View:- 视图:-

<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>

In this used html.validation summary 在此使用html.validation摘要

In this Form it should show asterisk (*) sign below textbox and error in validation summary 在此表单中,它应在文本框下方显示星号(*),并在验证摘要中显示错误

how to achieve it? 怎么实现呢?

Can't you use the Required attribute in your model? 您不能在模型中使用Required属性吗?

Example: 例:

public class ClassName{

[Required(ErrorMessage = "* Please enter Item Name")]
public string ItemName {get;set;}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM