本文转自: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

最新文章

  1. 设置Hyper V
  2. T 恤
  3. semanage: 未找到命令
  4. 自制Javascript分页插件,支持AJAX加载和URL带参跳转两种初始化方式,可用于同一页面的多个分页和不同页面的调用
  5. 程序猿必要10免费的钱jquery小工具
  6. Linux - 进程间通信 - 匿名管道
  7. Ant Design UI组件
  8. &lt;Mastering KVM Virtualization&gt;:第三章 搭建独立的KVM虚拟化
  9. python基于selenium实现自动删除qq空间留言板
  10. Python学习之MySQLdb模块
  11. ES6中的箭头函数和普通函数有什么区别?
  12. VMware Workstation 14 激活码
  13. 学习笔记TF040:多GPU并行
  14. JNI和NDK
  15. 【TOP100案例专访】当当网工程师林嘉琦谈双11大促经验及APM实践
  16. 使用Jmeter测试Dubbo接口(参数设置篇)
  17. 使用RegSetValueEx修改注册表时遇到的问题(转)
  18. template 的使用
  19. 初识python(python的安装与运行)
  20. 剑指offer 面试53题

热门文章

  1. JQuery UI - selectable
  2. leetcode Jump Game I II 待续 贪心看不懂啊!!!!
  3. SoftKeyboard在AndroidStudio下的配置和运行
  4. Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)
  5. cuda测试二维block的使用
  6. (Python OpenGL)【4】Uniform变量 PyOpenGL
  7. 最短路【洛谷P3393】 逃离僵尸岛
  8. 2017第八届蓝桥杯决赛(C++ B组)2.磁砖样式
  9. Java基础笔记(十九)——抽象类abstract
  10. SQL case when then end根据某列数据内容在新列显示自定义内容