当从非ajax执行方法时,我不需要做什么。我知道如何检测ajax请求,但我不知道应该返回什么只是为了忽略。
public class AjaxOnlyAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!filterContext.HttpContext.Request.IsAjaxRequest())
{
filterContext.Result = ???;
}
}
}
[AjaxOnly]
public async Task<ActionResult> AjaxOnlyMethod()
{
//This is method should be ignore if not ajax request
}
答案 0 :(得分:0)
试试这个我认为你可以重定向到其他一些动作方法,如果请求是Ajax的话会返回一个错误视图
喜欢
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(new { action = "SomeOtherActionMethodName" }));