码迷,mamicode.com
首页 > 其他好文 > 详细

[转]how can I change default errormessage for invalid price

时间:2014-09-19 13:37:35      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   java   ar   for   

本文转自:http://forums.asp.net/t/1598262.aspx?how+can+I+change+default+errormessage+for+invalid+price

I have:

[Required(ErrorMessage = "Price is required.")] public decimal price { get; set; }

How can I change default message for invalid price - I would like to change default error message "The value ‘45,8asasa‘ is not valid for Price.".

 

You cannot change this unforunately.
 See,
 http://forums.asp.net/p/1512140/3606268.aspx


 But using a javascript hack you can change the error message though,
 Just put this right after form closing tag,
 <script type="text/javascript">
             var vald = window.mvcClientValidationMetadata[0][Fields];
             for (var i = 0; i < vald.length; i++) {
                 for (var j = 0; j < vald[i].ValidationRules.length; j++) {
                     if (vald[i].ValidationRules[j].ErrorMessage.indexOf("must be a number.") > -1) {
                         vald[i].ValidationRules[j].ErrorMessage = vald[i].FieldName +" Error";
                     }
                 }
             }
         </script>

At server side you easily change it by playing with ModelState 

 

[转]how can I change default errormessage for invalid price

标签:style   blog   http   color   io   os   java   ar   for   

原文地址:http://www.cnblogs.com/freeliver54/p/3981139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!