我们可以通过HTTP请求头来判断是否为Ajax请求,Ajax请求的request headers里都会有一个key为x-requested-with,值为XMLHttpRequest的header 所以我们可以添加一个扩展方法: public static bool IsAjax(this HttpRequest req) { bool result = false; var xreq = req.Headers.ContainsKey("x-requested-with"); if
using System; namespace System.Web.Mvc { /// <summary>Represents a class that extends the <see cref="T:System.Web.HttpRequestBase" /> class by adding the ability to determine whether an HTTP request is an AJAX request.</summary>