I am building a ASP.NET MVC4(.5) web app. I went trough much topics about the problem, tried every one of them but the problem didn't disappear.
I have a controller which returns a PartialView.
[HttpGet]
public ActionResult Subcategories(int id)
{
IOrderedQueryable<Subcategory> subcategories = this.Data.Subcategories
.All()
.Where(sub => sub.Category.Id == id)
.OrderBy(cat => cat.Name);
var request = this.Request.IsAjaxRequest();
IEnumerable<ConciseSubcategoryViewModel> model = Mapper.Map<IEnumerable<ConciseSubcategoryViewModel>>(subcategories);
return this.PartialView("_Subcategories", model);
}
I have this bundle, included in the bottom of my _Layout page.
bundles.Add(new ScriptBundle("~/Content/jquery").Include(
"~/Scripts/jquery-1.10.2.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery.unobtrusive-ajax.js",
"~/Scripts/jquery.validate.unobtrusive.js"));
But, when I create Ajax.ActionLink in one of my views and call it, the variable "request" in the controller has value "false", the cause of the request is DOCUMENT instead of XHR and returns the partial view in new tab of the browser.
@Ajax.ActionLink(
Model.Name,
"Subcategories",
"Items",
new { Id = Model.Id },
new AjaxOptions() {
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "subcategories-wrapper"
})
Thanks for the help.I just can't see anything wrong.
So guys I don't think the problem is here but, see what happens when I return the view, which creates the ajax:
In the
_Categories
view:And the ConciseCategoryViewModel
I think that it can still use the unobtrusive, included in the _Layout page...