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

@Scripts.Render("~/bundles/jquery")  
//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
<script>
  $(document).bind("mobileinit", function () {
    $.mobile.ajaxEnabled = false;
  });
</script>
@Scripts.Render("~/bundles/jquerymobile")  

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

Comments

Popular posts from this blog

Tibco Rendezvous (tibrv) C# .Net example

Parse XML to dynamic object in C#