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

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

Assume this model:

Public Class Detail
    ...
    
    
         


        
14条回答
  •  鱼传尺愫
    2020-11-28 04:06

    You can override the message by supplying the data-val-number attribute yourself when rendering the field. This overrides the default message. This works at least with MVC 4.

    @Html.EditorFor(model => model.MyNumberField, new { data_val_number="Supply an integer, dude!" })

    Remember that you have to use underscore in the attribute name for Razor to accept your attribute.

提交回复
热议问题