Ajax.BeginForm OnSuccess not firing
Add reference to the following js libraries:
- jquery-{version}.min.js
- MicrosoftAjax.js
- MicrosoftMvcAjax.js
- jquery.validate.min.js
- jquery.validate.unobtrusive.js
- jquery.unobtrusive-ajax.js
Assuming you have a brand new project, you need to do the following things to get this working. The ASP.NET MVC template does not support unobtrusive AJAX out of the box:
- Add the "Microsoft.jQuery.Unobtrusive.Ajax" package from Nuget into your project. You can do this by right-clicking on the project and choosing "Manage Nuget Packages."
Add "jquery.unobtrusive-ajax.js" to your page. If you're using the "bundling" feature in System.Web.Optimization, one easy way would be to add it to the jQuery bundle:
bundles.Add(new ScriptBundle("~/bundles/jquery") .Include("~/Scripts/jquery-{version}.js") .Include("~/Scripts/jquery.unobtrusive-ajax.js"));
You can also just add a
<script>
tag that points to the script.
Assuming the page is loading jQuery and jquery.unobtrusive-ajax.js, the code you posted should work.