这应该是一个非常简单的任务 - 从基本控制器重定向。这是一个示例性参考,但不包括我遇到的错误:Redirecting from OnActionExecuting in a Base Controller
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (myObject == null) {
// System.InvalidOperationException: The matched route does not include a 'controller' route value, which is required.
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {{ "controller", "controllerName"}, {"action", "actionName"}});
// Throws the same exception:
filterContext.Result = RedirectToAction("actionName", "controllerName");
}
}
http://localhost/controllerName/actionName?controller=controllerName&action=actionName
调试时,传递给Result属性的重定向对象包含控制器和操作值。在返回的URL中,它也存在。
为什么抱怨没有控制器价值?除了普通格式之外,为什么它还会在查询字符串中显示控制器和操作值?
// hard coded URL produces the same result. What am I misunderstanding?
filterContext.Result = new RedirectResult("~/Employee/Create");