asp.net mvc validation must be a number custom error

前端 未结 10 1348
时光取名叫无心
时光取名叫无心 2021-02-06 01:14

I am new to asp.net and I have a problem. When the users insert in a editor for a decimal field something other than numbers, they get an error \"Field name\" is not a number. B

10条回答
  •  没有蜡笔的小新
    2021-02-06 01:35

    You can set ResourceClassKey of ClientDataTypeModelValidatorProvider class to name of a global resource that contains FieldMustBeNumeric key to replace mvc validation error message of number with your custom message. Also key of date validation error message is FieldMustBeDate.

    ClientDataTypeModelValidatorProvider.ResourceClassKey="MyResources"; // MyResource is my global resource
    

    See here for more details on how to add the MyResources.resx file to your project:

    The field must be a number. How to change this message to another language?

提交回复
热议问题