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

后端 未结 7 2068
梦毁少年i
梦毁少年i 2020-11-27 02:50

I\'m using ASP .NET MVC 3 with Data Annotations and the jQuery validate plugin.

Is there a way to mark that a certain field (or certain data annotation) should only

7条回答
  •  感情败类
    2020-11-27 03:50

    MVC5 use jquery.validate

    http://jqueryvalidation.org/rules/

    If you want to remove validations in MVC5 client-Side you need to do the following:

    Remove all validations on 'myinput'

    $("#myinput").rules("remove");
    

    Specific validations

    $("#myinput").rules("remove", "min max" );
    

    Listing the validations can help

    $("#myinput").rules();
    

    Then you will need to correct your Code Behind to validate manually your model or differently because ModelState.IsValid will be false. Using ModelState.Clear() and TryValidateModel can then be handy.

    Edit:

    Disabling the control also remove the validations.

    $("#myinput").attr('disabled', disabledValue);
    

提交回复
热议问题