I'm using asp.net mvc2 for my application. I have an ajax request sent using jQuery.
$.ajax{(
url:'/home/index'
type:'post',
data:$('#myform').serialize(),
dataType:'html',
success:function(response)
{
//update relevant document portion
}
});
Here is my controller method
public ActionResult index(Book book)
{
Repository _repo = new Repository();
_repo.Add(book);
_repo.Save();
if(Request.IsAjaxRequest())
{
return RedirectToAction("List",new{id=book.id});
}
//do something else
}
public ActionResult List(int id)
{
if(Request.IsAjaxRequest())/* here it always returns false even though its been redirected from an ajax request to get here*/
{
//do something
}
}
In index actionresult Request.IsAjaxRequest() works properly but when its redirected to List actionresult it does not identify it as ajax request. how can I know that list is being called from an ajax redirection?
Edit
Request.IsAjaxRequest is returning true in IE for both index and List methods while in firefox Request.IsAjaxRequest is true only for index method. When I inspect the code for ajax request I could see two of them; first is post to index method and second is Get from List method. IE sends x-requested-with header with both requests while Firefox is sending this header only for first request destined to index method.
How can I make Firefox work like IE (in this scenario only) i.e sending x-requested-with header with both request in case when second request is not originated from client but is a redirection from first request.