Ajax.ActionLink not working, Response.IsAjaxRequest() is always false

前端 未结 3 815
刺人心
刺人心 2020-12-13 06:58

I have been googling/SO:ing this issue for a while and many seem to be sharing this, but I haven\'t found any successful solution to my problem.

Using MVC3 and Razor

3条回答
  •  余生分开走
    2020-12-13 07:57

    Another IE-specific issue that can keep ActionLink from functioning correctly is covered here: ASP.NET MVC - Prevent Cache on Ajax.ActionLinks

    Basically, IE sometimes caches Ajax GET requests, so setting the AjaxOption's HttpMethod to POST is a less fragile way to construct an ActionLink:

    @Ajax.ActionLink(
           item.Name + " (Ajax link test)",
             "MyActionName",
             routeValues: new { id = item.Id },
             ajaxOptions: new AjaxOptions()
             {
                  UpdateTargetId = "divToUpdate",
                  InsertionMode = InsertionMode.Replace,
                  HttpMethod = "POST"
             })
    

提交回复
热议问题