DataAnnotations validation (Regular Expression) in asp.net mvc 4 - razor view

前端 未结 9 2117
甜味超标
甜味超标 2020-11-28 08:12

The DataAnnotations validator not working in asp.net mvc 4 razor view, when using the special characters in the regular expression.

Model:



        
9条回答
  •  孤城傲影
    2020-11-28 08:34

    UPDATE 9 July 2012 - Looks like this is fixed in RTM.

    1. We already imply ^ and $ so you don't need to add them. (It doesn't appear to be a problem to include them, but you don't need them)
    2. This appears to be a bug in ASP.NET MVC 4/Preview/Beta. I've opened a bug

    View source shows the following:

    data-val-regex-pattern="([a-zA-Z0-9 .&'-]+)"                  <-- MVC 3
    data-val-regex-pattern="([a-zA-Z0-9 .&amp;&#39;-]+)"      <-- MVC 4/Beta
    

    It looks like we're double encoding.

提交回复
热议问题