How to change 'data-val-number' message validation in MVC while it is generated by @Html helper

后端 未结 14 1721
面向向阳花
面向向阳花 2020-11-28 03:44

Assume this model:

Public Class Detail
    ...
    
    
         


        
14条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 04:20

    What you have to do is:

    Add the following code inside Application_Start() in Global.asax:

     ClientDataTypeModelValidatorProvider.ResourceClassKey = "Messages";
     DefaultModelBinder.ResourceClassKey = "Messages";
    

    Right click your ASP.NET MVC project in VS. Select Add => Add ASP.NET Folder => App_GlobalResources.

    Add a .resx file called Messages.resx in that folder.

    Add these string resources in the .resx file:

    FieldMustBeDate        The field {0} must be a date.
    FieldMustBeNumeric     The field {0} must be a number.
    PropertyValueInvalid   The value '{0}' is not valid for {1}.
    PropertyValueRequired  A value is required.
    

    Change the FieldMustBeNumeric value as you want... :)

    You're done.


    Check this post for more details:

    Localizing Default Error Messages in ASP.NET MVC and WebForms

提交回复
热议问题