eZeeNow.com

it's your's

How to Enable and Disable Client-Side Validation in MVC?

 

Client validation is enabled in the ASP .NET MVC3 and MVC4 application by default. The behavior is defined in Web.config settings in MVC4. Open the Web.config file in app settings section:

<appSettings> 
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

We can turn off the validation in the application by changing the value to false in MVC4.

Enabling and Disabling Client-Side Validation for Specific View

@{
 Html.EnableClientValidation(false);
Html.EnableUnobtrusiveJavaScript(false);
}

 Using JQuery.

PaymentTokenID is ElementID  and hiddden is the dummy class that we are using to ignore the validation part.

$('#PaymentTokenId').on('Change', function (event) { 
$("input,select").addClass("hiddden");
 var settings = $.data($('form').get(0), 'validator').settings;
settings.ignore = ".hiddden";
 });

Using JQuery ICheck plugin

$('#PaymentTokenId').on('ifChecked', function (event) { 
$("input,select").addClass("hiddden");
 var settings = $.data($('form').get(0), 'validator').settings;
settings.ignore = ".hiddden";
 });
Loading