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

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

Assume this model:

Public Class Detail
    ...
    
    
         


        
14条回答
  •  难免孤独
    2020-11-28 04:27

    As an alternate way around this, I applied a RegularExpression attribute to catch the invalid entry and set my message there:

    [RegularExpression(@"[0-9]*$", ErrorMessage = "Please enter a valid number ")]
    

    This slightly a hack but this seemed preferable to the complexity the other solutions presented, at least in my particular situation.

    EDIT: This worked well in MVC3 but it seems that there may well be better solutions for MVC4+.

提交回复
热议问题