Tips in ASP.NET MVC

Enabling and Disabling Client-Side Validation Globally

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

From Code
protected void Application_Start()
{
//Enable or Disable Client Side Validation at Application Level
HtmlHelper.ClientValidationEnabled = true;
HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
}

Disable validation for a single field in client side

@Html.TexBoxFor(model => model.SomeValue,                  
new Dictionary<string, object> { { "data-val", false }}) 

Enabling and Disabling Client-Side Validation for Specific View

@model MvcApp.Models.SampleModel
@{
ViewBag.Title = "Home";
HtmlHelper.ClientValidationEnabled = false;
}

Enjoy reading

2 thoughts on “Tips in ASP.NET MVC

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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