c# - ASP .NET MVC Disable Client Side Validation at Per-Field Level -


i'm using asp .net mvc 3 data annotations , jquery validate plugin.

is there way mark field (or data annotation) should validated server-side?

i have phone number field masking plugin on it, , regular expression validator goes crazy on user's end. regex fail-safe (in case decides hack javascript validation), don't need run on client side. i'd still other validation run client side.

i'm not sure if solution works on mvc3. surely works on mvc4:

you can disable client side validation in razor view prior render field , re-enable client side validation after field has been rendered.

example:

<div class="editor-field">     @{ html.enableclientvalidation(false); }     @html.textboxfor(m => m.batchid, new { @class = "k-textbox" })     @{ html.enableclientvalidation(true); } </div> 

here disable client side validation batchid field.

also have developed little helper this:

public static class ynnovahtmlhelper {     public static clientsidevalidationdisabler begindisableclientsidevalidation(this htmlhelper html)     {         return new clientsidevalidationdisabler(html);     } }  public class clientsidevalidationdisabler : idisposable {     private htmlhelper _html;      public clientsidevalidationdisabler(htmlhelper html)     {         _html = html;         _html.enableclientvalidation(false);     }      public void dispose()     {         _html.enableclientvalidation(true);         _html = null;     } } 

you use follow:

<div class="editor-field">     @using (html.begindisableclientsidevalidation()) {         @html.textboxfor(m => m.batchid, new { @class = "k-textbox" })     } </div> 

if has better solutions please let me know!

hope help.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -