如何创建仅与AJAX请求匹配的自定义路由约束?
在控制器中,我可以使用Request.IsAjaxRequest()。
如何从我的自定义约束访问IsAjaxRequest?我实现了IRouteConstraint接口和Match()方法,如下所示:
public class IsAjaxConstraint : IRouteConstraint
{
public bool Match(HttpContextBase httpContext,
Route route,
string parameterName,
RouteValueDictionary values,
RouteDirection routeDirection)
{
// How can I check for an Ajax request here?
}
}发布于 2012-01-29 10:13:09
如果将其添加到路由约束中,httpContext.Request.IsAjaxRequest()是否起作用?
using System.Web.Mvc;Request.IsAjaxRequest()是System.Web.Mvc中的一个扩展方法。
https://stackoverflow.com/questions/9049597
复制相似问题