MVC5 Ajax form is not updating DIV but replacing the whole page instead

March 15, 2015 by Anuraj

.Net ASP.Net MVC HTML5 Javascript

While working on MVC5 application, I faced this issue, I was using Ajax.BeginForm() and from controller, I was returning content result. But instead of updating the DIV, the content was opened in new Tab. Initially I thought it was due to some javascript error, but it was not working with Ajax.ActionLink also. Later I found it was due to missing “Microsoft.jQuery.Unobtrusive.Ajax” package. You can install this via NuGet.

NuGet package - Microsoft.jQuery.Unobtrusive.Ajax

And include it in the BundleConfig.cs.

bundles.Add(new ScriptBundle("~/bundles/jqueryunobtrusive").Include(
            "~/Scripts/jquery.unobtrusive*"));

And include the jqueryunobtrusive in _layout.cshtml file.

@Scripts.Render("~/bundles/jqueryunobtrusive")

It will resolve this issue.

Happy Programming :)

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub