Validation enable disable at client side MVC


We can easily enable/ disable validation of any field on client side using following code.

@{ Html.EnableClientValidation(false); }

@{ Html.EnableClientValidation(true); }



If in model class we have all the properties with isrequired parameter and we need to set isrequired = false for any one of them then use the above syntax to enable and disable the validation at client side

@{ Html.EnableClientValidation(false); }

@Html.TextBoxFor(m => m.Lastname, new { @class = “mytextbox” })

@{ Html.EnableClientValidation(true); }

By using above code Lastname property will not be validate (even if we have assigned it as a [DataMember(IsRequired = true)] in model class file)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s