I have updated an app from ASP.NET MVC 3 to ASP.NET MVC 4.
The app worked fine in MVC 3. The only thing that isn\'t working in MVC 4 is Ajax.Be
OK, I have solved this.
In the MVC 3 app, I had commented out the following in the web.config:
<appSettings>
<add key="webpages:Version" value="1.0" />
<!--<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />-->
</appSettings>
This explains why asp.net mvc 3 was not rendering html 5.
In the new mvc 4 app, the default setting has ClientValidationEnbled=true
and UnobstrusiveJavaScriptEnabled=true
, as follows:
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
...
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
So my app needed the following javascript files to be included:
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
And it needed the microsoft*.js files throwing away, ie:
@*<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcValidation.js")" type="text/javascript"></script>*@
I figured this out after reading @Darin Dimitrov's reply to the following question:
Are MicrosoftAjax.js, MicrosoftMvcAjax.js and MicrosoftMvcValidation.js obsolete as of ASP.NET MVC 3?
Many thanks to Darin. The answer is worth reading, to enlighten yourself as to the meaning of the two appSettings I had disabled.