C# ErrorMessage在验证应用程序块6中不起作用

C# ErrorMessage在验证应用程序块6中不起作用,c#,validation,asp.net-mvc-4,razor,C#,Validation,Asp.net Mvc 4,Razor,当我使用如下属性时,VAB6有一个问题 [NotNullValidator(ErrorMessage="Name must be not null")] [StringLengthValidator(1, RangeBoundaryType.Inclusive, 5,RangeBoundaryType.Inclusive,ErrorMessage="Length Error")] public string Name { get; set; } @Html.ValidationSummary(

当我使用如下属性时,VAB6有一个问题

[NotNullValidator(ErrorMessage="Name must be not null")]
[StringLengthValidator(1, RangeBoundaryType.Inclusive, 5,RangeBoundaryType.Inclusive,ErrorMessage="Length Error")]
public string Name { get; set; }
@Html.ValidationSummary()
显示未指定的默认错误消息

名称不能为null>该值不能为null

长度错误>>值的长度必须在范围内 “1”(含)-“5”(含)


为什么VAB 6强制我使用默认消息?

您对NotNullValidator属性使用了错误的限定符。请尝试以下方法:

[NotNullValidator(MessageTemplate="Name must be not null")]
有关更多详细信息,请参阅