I have an MVC project in which I have a form with a submit button. I have added a jquery client-side handler that intercepts the form submit event. The javascript function calls the same MVC action that would have been called without the javascript.
$("form[action ='/List/CreateItem']").submit(
function() {
$.post($(this).attr("action"), $(this).serialize(), function(response) { $("#results").html(response); });
return false;
}
);
In the MVC action that is called, I test for Request.IsAjaxRequest to decide whether to return a view or a JSON result. My problem is that Request.IsAjaxRequest is returning false, even though I know the call is being made from the jquery function. (I know this because if I comment out the $.post line in the jquery function and just leave the return false line, nothing happens. If I un-comment the line, the action gets executed - but it returns the view because IsAjaxRequest is false.)
Should this line cause Request.IsAjaxRequest to be true?