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

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.

Leave a Comment