如何在ASP.NET MVC中使用动作过滤器来路由到不同的视图但使用相同的URL?

Bra*_*ton 2 asp.net-mvc asp.net-mvc-3

是否有可能制作一个过滤器,在(主要)处理控制器动作之后,检查某个测试条件并透明地路由到用户的不同视图(即URL没有变化)?

这是我对某些伪代码的最佳猜测:

    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        // If some condition is true
        //  Change the resulting view resolution to XYZ

        base.OnResultExecuting(filterContext);
    }
Run Code Online (Sandbox Code Playgroud)

Dar*_*rov 7

filterContext.Result = new ViewResult
{
    ViewName = "~/Views/SomeController/SomeView.cshtml"
};
Run Code Online (Sandbox Code Playgroud)

这将使操作的执行短路.