how to detect when a page is called using ajax in asp.net mvc ?
There is no specific way to determine if the call was made by javascript or directly in the browser, as it is a regular http call.
You can add a header to your ajax call to distinguish it from other calls, or possibly add a parameter to the query string that is only used on ajax calls.
ASP.NET MVC ajax does add such a header - X-Requested-With: XMLHttpRequest
, which you can use to sniff that this is an ajax call by the mvc ajax library. However, if you are using jQuery or your own hand rolled ajax calls, this will not be set. Additionally, other clients might spoof this header (using WebClient, for example) so finding it is not a guarantee that an ajax call has been made.