Fix for MVC4 RC Mobile with AJAX

In default MVC4 RC Mobile Application project ajax doesn’t seem to work correctly. For some reason this few lines were removed from MVC4 RC (it was there in MVC4 Beta)

$(document).bind("mobileinit", function () {
  // As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g.,
  // when navigating from a mobile to a non-mobile page, or when clicking "back"
  // after a form post), hence disabling it.
  $.mobile.ajaxEnabled = false;

To fix it you need to add the lines above before jquerymobile script

//add unobtrusive-ajax just like in normal web application
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
//and disable mobile ajax just like in beta release
  $(document).bind("mobileinit", function () {
    $.mobile.ajaxEnabled = false;

Then all the functionality from How to use MVC3 with AJAX post will work correctly in Mobile application.


Popular posts from this blog

Parse XML to dynamic object in C#

C# Updating GUI from different thread