Asp.net mvc 如何在mvc中显示带星号的验证摘要?

Asp.net mvc 如何在mvc中显示带星号的验证摘要?,asp.net-mvc,validation,validationsummary,Asp.net Mvc,Validation,Validationsummary,在此表单中,使用了错误的验证摘要 视图:- @ValidationSummary(false,“请更正以下详细信息:”,new{@class=“text danger”}) @LabelFor(Model=>Model.ItemName,新的{style=“font-weight:bold;”,@maxlength=“100”}) @Html.TextBoxFor(Model=>Model.ItemName) @Html.ValidationMessageFor(Model=>Model.It

在此表单中,使用了错误的验证摘要

视图:-


@ValidationSummary(false,“请更正以下详细信息:”,new{@class=“text danger”})
@LabelFor(Model=>Model.ItemName,新的{style=“font-weight:bold;”,@maxlength=“100”})
@Html.TextBoxFor(Model=>Model.ItemName)
@Html.ValidationMessageFor(Model=>Model.ItemName)
@Html.LabelFor(Model=>Model.ActiveProductGroup,新的{style=“font-weight:bold;”“})
@Html.DropDownListFor(Model=>Model.ProductGroupID,新建选择列表(ViewBag.ActiveProductGroup,“Value”,“Text”),“--Select Value--”,新建{style=“Width:95%”)
@Html.ValidationMessageFor(Model=>Model.ActiveProductGroup)
@Html.LabelFor(Model=>Model.SequenceNumber,新的{style=“font-weight:bold;”“})
@Html.TextBoxFor(Model=>Model.SequenceNumber,新的{style=“text align:right”,@maxlength=“3”})
@Html.ValidationMessageFor(Model=>Model.SequenceNumber)
@Html.LabelFor(Model=>Model.UnitPrice,新的{style=“font-weight:bold;”“})
@Html.TextBoxFor(Model=>Model.UnitPrice,新的{style=“text align:right”,@maxlength=“5”})
@Html.ValidationMessageFor(Model=>Model.UnitPrice)
@LabelFor(Model=>Model.Quantity,新的{style=“font-weight:bold;”})
@Html.TextBoxFor(Model=>Model.Quantity,新的{style=“text align:right”,@maxlength=“5”})
@Html.ValidationMessageFor(Model=>Model.Quantity)
@LabelFor(Model=>Model.EstimatedDeliveryDays,新的{style=“font-weight:bold;”})
@Html.TextBoxFor(Model=>Model.EstimatedDeliveryDays,新的{style=“text align:right”,@maxlength=“2”})
@Html.ValidationMessageFor(Model=>Model.EstimatedDeliveryDays)
在此使用的html.validation摘要中

在此表单中,文本框下方应显示星号(*)符号,并在验证摘要中显示错误


如何实现它?

您不能在模型中使用必需的属性吗

例如:

public class ClassName{

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

}

您不能在模型中使用必需的属性吗

例如:

public class ClassName{

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

}

类似于
@Html.ValidationMessageFor(Model=>Model.ItemName,“*”)
的东西可能会起作用,因为CSS文件已经包括在内。@Tetsuyayayamamoto尝试过!!!!在验证之前,它在文本框下方显示*符号,表示您需要CSS样式并使用
div
。你能在图像中显示星号应该放在哪里吗?@TetsuyaYamamoto需要在项目名称文本框下放置星号你是否尝试过在
RequiredAttribute
中添加星号,如
[必需(ErrorMessage=“*请输入项目名称”)]
?如果不成功,使用包含星号的开关
span
应该是您最后的选择。类似
@Html.ValidationMessageFor(Model=>Model.ItemName,“*”)
的东西可能会起作用,因为CSS文件已经包括在内。@TetsuyaYamamoto尝试过!!!!在验证之前,它在文本框下方显示*符号,表示您需要CSS样式并使用
div
。你能在图像中显示星号应该放在哪里吗?@TetsuyaYamamoto需要在项目名称文本框下放置星号你是否尝试过在
RequiredAttribute
中添加星号,如
[必需(ErrorMessage=“*请输入项目名称”)]
?如果不成功,使用包含星号的开关
span
应该是您最后的选择。