I am using Asp.net MVC3 and trying to do a simple Ajax post to the server which returns a partial view and updates my list of items during a search.
@usi
var controllerContext = MockRepository.GenerateMock<ControllerContext>();
controllerContext.Expect(c => c.HttpContext.Request["X-Requested-With"]).Return("XMLHttpRequest");
controller.ControllerContext = controllerContext;
Make sure that the jquery.unobtrusive.ajax.js / jquery.unobtrusive.ajax.min.js script file is referenced after the other jquery script files, also make sure that you dont reference the file more than once per page and you should be sorted
You need to add the unobtrusive script after jquery script like this.
bundles.Add(new ScriptBundle("~/bundles/searchDemo").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui-{version}.js",
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
I stumbled on the similar situation where IsAjaxRequest() didn't work. I made sure Microsoft unobtrusive package is included. It still didn't help. Just upgraded to the latest version of unobtrusive library from package manager and it worked!
You're including the unobtrusive-AJAX script before jQuery, so none of your scripts are working.