如何关闭.net MVC中字段的默认错误消息之一 [英] How to turn off one of the default error messages on a field in .net MVC

查看:75
本文介绍了如何关闭.net MVC中字段的默认错误消息之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC中的模型中具有以下内容:

I have the following in a model in MVC:

[DataType(DataType.Currency, ErrorMessage="*")]
        [Required(ErrorMessage="*")]
        [Range(.50,double.MaxValue, ErrorMessage="*")]
        public Decimal PaymentAmount{get;set;}



当我使用编辑器进行此字段的验证时,它工作得很好,但有一个例外.如果我开始输入并到达25.那么我会收到一条错误消息字段PaymentAmount必须为数字".

我的布局是这样的,我不想长的错误消息.因此,当您键入某些内容(例如,可能要完成键入25.0或25.5)时布局中断时,这将成为一个非常糟糕的可用性问题.我已经在所有可以找到的注释上设置了错误消息,但是我仍然可以理解.关于我所缺少的任何提示吗?

感谢所有花时间回答这个问题的人

Danny



When I use the editor for, and the validation for this field, it works pretty well with one exception. If I start typing and get to 25. then I get an error message "The field PaymentAmount must be a number".

My layout is such that I don''t want long error messages. So it becomes a really bad usability deal when the layout breaks while you are typing something that you are likely going to finish typing to say 25.0 or 25.5 for example. I have set the error message on all the annotations that I can find, but I still get that. Any tips for what I am missing?

thanks to all who take the time to answer this one

Danny

推荐答案

放置您的错误消息,替换为您的消息":
它应该可以工作...

place your error message, replace of "your message":
it should be working...

[DataType(DataType.Currency, ErrorMessage="your message")]
        [Required(ErrorMessage="*")]
        [Range(.50,double.MaxValue, ErrorMessage="your message")]
        public Decimal PaymentAmount{get;set;}


这篇关于如何关闭.net MVC中字段的默认错误消息之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆