本文转自: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的更多相关文章

  1. JDK Environment Variable And Change default JDK

    Environment Variable : change(import) /etc/bashrc export JAVA_HOME=/software/jdk1.8.0 export PATH=$J ...

  2. How to Change Default Web ADI Upload Parameters for FlexField Import / Validation

    How to Change Default Web ADI Upload Parameters for FlexField Import / Validation (文档 ID 553345.1) 转 ...

  3. Change default network name (ens33) to old “eth0” on Ubuntu 18.04 / Ubuntu 16.04

    Change default network name (ens33) to old “eth0” on Ubuntu 18.04 / Ubuntu 16.04 By Raj Last updated ...

  4. windows 10 change default program bug

    windows 10 change default program bug https://www.isumsoft.com/windows-10/how-to-change-or-set-defau ...

  5. CHANGE DEFAULT FTP PORT FOR VSFTP

    http://twincreations.co.uk/change-default-ftp-port-for-vsftp/ http://www.cnblogs.com/kuliuheng/p/320 ...

  6. [WebStrom] Change default cmd to Cygwin

    GO to setting, search Terminal: Change shell path : C:\cygwin\bin\bash.exe --login -i    (to the loc ...

  7. How to change default root@ email address linux / postfix / centos?

    Change root@hostname to different email address By default, any email sent by system is sent to root ...

  8. 改变Prompt默认路径,Change Default Visual Studio Command Prompt Location

    在项目中经常需要使用 Visual Studio Command Prompt编译项目,每次启动时都是默认进入 C:\windows\system32> 目录, 需要cd切换路径,如果把Visu ...

  9. unity, 不要change Default sharedMaterial

    假设在场景中加一个sprite,其材质使用默认的Sprites-Default. 若调用: Color color=sprite.GetComponent<SpriteRenderer>( ...

随机推荐

  1. C++面试笔记--字符串

    基本上求职者进行笔试没有不考字符串的.字符串也是一种相对简单的数据结构,容易被考.事实上,字符创也是一个考验程序猿编程规范和编程习惯的重要考点. 1.替换空格:实现一个函数,把字符串中的每个空格替换成 ...

  2. Metasploit 读书笔记-神器Meterpreter

    一、基本命令 截屏 screenshot 2.获取系统平台信息 sysinfo 3.进程信息 ps 4.获取键盘记录 查看进程信息ps--migrate将会话迁移至explorer.exe进程空间中- ...

  3. 如何在Linux上使用x2go设置远程桌面

    Until ACS supports Spice, if ever,you're better off with "on-VM" softare such RDP for Wind ...

  4. Centos7 调整磁盘空间

    1. 查看磁盘空间占用情况:  df -h 可以看到 /home 有很多剩余空间, 而节点较少. 2. 备份 /home 下的内容: cp -r /home/ homebak/ 3. 关闭home进程 ...

  5. findControl 可以获取前台页面的控件

    findControl 可以获取前台页面的控件

  6. Vue知识分享一

    最近想着把之前学的Vue的知识整理一下,方便在公司和同事一起分享.我想要按照下面几个方面去说一下,我对vue的学习理解. 一.什么是VUE vue.js是一个用来开发Web界面的前端库,是很轻量级的工 ...

  7. ajax遍历数据生成下拉框

    <script type="text/javascript">        function GetEQIDList(ModuleID)    {        $. ...

  8. MVC与三层的区别

    闲来无事,想了想MVC与三层的区别,根据自己的经验,上图 由此来看,其实这两种框架(结构)的分层方式其实没什么联系,也没有什么可比性,但他们的目的都一样的:解耦 --Ones

  9. kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence

    Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...

  10. Cocoapds pod install时报错 :The sandbox is not sync with the Podfile.lock

    解决方法简单:仅供其他小伙伴参考 删除项目工程本地文件夹中的xxx.workspace和Podfile.lock文件,然后重新pod install即可