asp.net-mvc - 如何从 ActionFilter 中跳过操作执行?

标签 asp.net-mvc action-filter

OnActionExecuting中满足特定条件时,是否可以跳过整个操作方法执行并返回特定的ActionResult

最佳答案

您可以为此使用filterContext.Result。它应该看起来像这样:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    //Check your condition here
    if (true)
    {
        //Create your result
        filterContext.Result = new EmptyResult();
    }
    else
        base.OnActionExecuting(filterContext);
}

关于asp.net-mvc - 如何从 ActionFilter 中跳过操作执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9837180/

相关文章:

c# - EntityFramework ORM 错误插入

asp.net-mvc - 在 ASP.NET MVC 的模型中调用 UrlHelper

asp.net - ASP.NET MVC 中的 NHibernate 事务管理 - 应该如何完成?

c# - 如何将参数传递给通用操作过滤器

c# - ASP.NET MVC 5 Bootstrap 按钮移动到另一个 View 页面

asp.net - MVC Controller 和 View 是否应该具有 1 对 1 的关系?

asp.net-mvc - 使用 ModelBinder 之前更改区域性

asp.net-mvc - 登录后立即在 ActionFilter 中检查 User.Identity.IsAuthenticated

c# - 如何在 NopCommerce 中实现 Action 过滤器

asp.net-mvc - Action 筛选执行顺序