I have a site in MVC4 using areas. In some area (let's call it Area) I have a controller (controller) with these actions:
public ActionResult Index()
{
return View();
}
public ActionResult OtherAction()
{
return View("Index");
}
This works fine if I do a simple redirect to Area / Controller / OtherAction as follows:
return RedirectToAction("OtherAction", "Controller", new { area = "Area" });
But I need ( check here why ) to do the redirection as follows:
RouteData routeData = new RouteData();
routeData.Values.Add("area", "Area");
routeData.Values.Add("controller", "Controller");
routeData.Values.Add("action", "OtherAction");
ControllerController controller = new ControllerController();
controller.Execute(new RequestContext(new HttpContextWrapper(HttpContext.ApplicationInstance.Context), routeData));
And in this case it will not work. After the last line, the OtherAction method is executed, and then in the last line of this code it throws this exception:
The "Index" view or its wizard is not found, or there is no viewing mechanism that supports the found locations. The following places were searched:
~ / Views / Controller / index.aspx
~ / Views / Controller / Index.ascx
~ / Views / Shared / index.aspx
~ / Views / Shared / Index.ascx
~/Views/Controller/Index.cshtml
~/Views/Controller/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
?