如何创建仅匹配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?
}
}
Run Code Online (Sandbox Code Playgroud)
如果将其添加到路径约束中,httpContext.Request.IsAjaxRequest()是否有效?
using System.Web.Mvc;
Run Code Online (Sandbox Code Playgroud)
Request.IsAjaxRequest()是System.Web.Mvc中的扩展方法.
| 归档时间: |
|
| 查看次数: |
491 次 |
| 最近记录: |