是否可以制作一个过滤器,在(大部分)处理完 Controller 操作后,检查特定的测试条件并向用户透明地路由到不同的 View (即 URL 中没有变化)?
这是我对一些伪代码的最佳猜测:
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
// If some condition is true
// Change the resulting view resolution to XYZ
base.OnResultExecuting(filterContext);
}
最佳答案
filterContext.Result = new ViewResult
{
ViewName = "~/Views/SomeController/SomeView.cshtml"
};
这将使 Action 的执行短路。
关于asp.net-mvc - 如何在 ASP.NET MVC 中使用操作过滤器路由到不同的 View 但使用相同的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7601681/