This should be a super easy task - redirecting from a base controller. Here's an exemplary reference, but does not cover the error I'm experiencing: Redirecting from OnActionExecuting in a Base Controller
Code:
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");
}
}
Rendered URL:
http://localhost/controllerName/actionName?controller=controllerName&action=actionName
When debugging, the redirect object passed to the Result property contains both a controller and action value. And in the returned URL it is also present.
Question:
Why is it complaining that there is no controller value? And why does it show the controller and action values in the query string in addition to the normal format?
Updated:
// hard coded URL produces the same result. What am I misunderstanding?
filterContext.Result = new RedirectResult("~/Employee/Create");