隐藏一个验证器类型但不是另一个MVC3的错误消息(Hiding error message for one validator type but not another MVC3)

编程入门 行业动态 更新时间:2024-10-25 16:19:02
隐藏一个验证器类型但不是另一个MVC3的错误消息(Hiding error message for one validator type but not another MVC3)

是否可以让ValidationMessageFor帮助程序仅显示字段验证程序之一的错误消息。 例如,如果我的模型中有一个字段,如下所示:

[Required] [Remote("SymbolUnique", "RemoteValidation", ErrorMessage = "A document already exists in the database for the entered symbol")] public string Symbol { get; set; }

我不希望显示所需的消息,只对正在突出显示的文本框的可视指示感到满意,但显示远程验证器的消息。 如果我将required属性的ErrorMessage参数设置为空字符串,则在设置ErrorMessage和ErrorMessageResourceName时会出现错误,因为框架开始过于聪明......

Is it possible to have a ValidationMessageFor helper only display the error message for one of the field's validators. For example if I had a field in my model like this:

[Required] [Remote("SymbolUnique", "RemoteValidation", ErrorMessage = "A document already exists in the database for the entered symbol")] public string Symbol { get; set; }

I wouldn't want to show the message for required, being happy with just the visual indication of the textbox being highlighted, but show the message for the remote validator. If I set the ErrorMessage parameter of the required attribute to an empty string I get an error for setting both the ErrorMessage and ErrorMessageResourceName as the framework starts being too clever...

最满意答案

我知道这很丑,但这会奏效

public class CustomeRequired : RequiredAttribute { public CustomeRequired() { this.ErrorMessage = ""; } }

I know it's ugly but this will work

public class CustomeRequired : RequiredAttribute { public CustomeRequired() { this.ErrorMessage = ""; } }

更多推荐

本文发布于:2023-08-04 14:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1416115.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   消息   类型   Hiding   message

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!