[转]how can I change default errormessage for invalid price
2024-10-20 07:51:01
本文转自: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
最新文章
- 设置Hyper V
- T 恤
- semanage: 未找到命令
- 自制Javascript分页插件,支持AJAX加载和URL带参跳转两种初始化方式,可用于同一页面的多个分页和不同页面的调用
- 程序猿必要10免费的钱jquery小工具
- Linux - 进程间通信 - 匿名管道
- Ant Design UI组件
- <;Mastering KVM Virtualization>;:第三章 搭建独立的KVM虚拟化
- python基于selenium实现自动删除qq空间留言板
- Python学习之MySQLdb模块
- ES6中的箭头函数和普通函数有什么区别?
- VMware Workstation 14 激活码
- 学习笔记TF040:多GPU并行
- JNI和NDK
- 【TOP100案例专访】当当网工程师林嘉琦谈双11大促经验及APM实践
- 使用Jmeter测试Dubbo接口(参数设置篇)
- 使用RegSetValueEx修改注册表时遇到的问题(转)
- template 的使用
- 初识python(python的安装与运行)
- 剑指offer 面试53题
热门文章
- JQuery UI - selectable
- leetcode Jump Game I II 待续 贪心看不懂啊!!!!
- SoftKeyboard在AndroidStudio下的配置和运行
- Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)
- cuda测试二维block的使用
- (Python OpenGL)【4】Uniform变量 PyOpenGL
- 最短路【洛谷P3393】 逃离僵尸岛
- 2017第八届蓝桥杯决赛(C++ B组)2.磁砖样式
- Java基础笔记(十九)——抽象类abstract
- SQL case when then end根据某列数据内容在新列显示自定义内容