Where is Request.IsAjaxRequest() in Asp.Net Core MVC?

前端 未结 4 1346
梦毁少年i
梦毁少年i 2020-11-30 04:10

To learn more about the new exciting Asp.Net-5 framework, I\'m trying to build a web application using the newly released Visual Studio 2015 CTP-6.

Most things looks

4条回答
  •  春和景丽
    2020-11-30 05:08

    For those who are working on ASP.Net Core

    HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest";
    

    Example
    Controller.cs

    bool isAjax = HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest";
    
    if (isAjax)
       return Json(new { redirectTo = Url.Action("Index", "ControllerAction") });
    else
       return RedirectToAction("Index", "ControllerAction");
    

提交回复
热议问题