I am trying to run this example Rendering Partial Views using ajax, but i got the following compilation error:
'HttpRequest' does not contain a definition for 'IsAjaxRequest' and no extension method 'IsAjaxRequest' accepting a first argument of type 'HttpRequest' could be found.
public ActionResult ItemsList(string ID)
{
Item item = Service.GetItemById(ID);
if (Request.IsAjaxRequest())
{
return PartialView("viewPath", item);
}
else
{
return View("viewPath", item);
}
}
Check the user agent, as this:
var isAjax = Request.Headers["X-Requested-With"] == "XMLHttpRequest"
|| Request.Headers["X-Requested-With"] == "Fetch";