This example shows you how to disable the page local caching in mvc asp.net. To disable page local caching we can write the below code by overriding OnActionExecuting method in controller instead of writing in each view in controller (or you can write in a common controller and each controller will be inherited from that common controller).

We can enable or disable the client side validations in MVC4 by doing simple configuration / code changes.

For enable / disable validations application level:

We can use any one of the below two methods (web.config change or Global.asax.cs change)

Configuration change in web.config

<appSettings>

<addkey="ClientValidationEnabled"value="true" />

<addkey="UnobtrusiveJavaScriptEnabled"value="true" />

</appSettings>

Code change in Global.asax.cs file

protectedvoid Application_Start()

{

HtmlHelper.ClientValidationEnabled = true;

HtmlHelper.UnobtrusiveJavaScriptEnabled = true;

}

For enable/disable validation in a particular view

set the below two properties in the View Razor code.

@{

ViewBag.Title = "Index";

HtmlHelper.ClientValidationEnabled = true;

HtmlHelper.UnobtrusiveJavaScriptEnabled = true;

}

Note:

In addition to the above changes for enable the client side validations we need to add the JQuery, jquery.validate, jquery.validate.unobtrusive js file reference in bundleconfig.cs and we have to consume them in the view.