[英]How to ignore execution of method from custom attribute?
I need to do nothing when method executed from not ajax. 从非ajax执行方法时,我无需执行任何操作。 I know how to detect ajax request, but I don't know what I should return just for ignore. 我知道如何检测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
}
Try this i think you can redirect to some other action method like the one which returns an error view if the request is Ajax 试试这个,我认为您可以重定向到其他一些操作方法,例如如果请求是Ajax则返回错误视图的方法
like 喜欢
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(new { action = "SomeOtherActionMethodName" }));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.