我在使用区域的MVC4中有一个站点。在某些区域(可以称之为区),我有一个控制器(Controller)这个动作:MVC控制器。执行区域
return RedirectToAction("OtherAction", "Controller", new { area = "Area" });
:
public ActionResult Index()
{
return View();
}
public ActionResult OtherAction()
{
return View("Index");
}
,如果我做一个简单的重定向到区/控制器/ OtherAction这样这个伟大的工程
但我需要(check here why)进行重定向这样的:
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));
而且在这种情况下,这是行不通的。最后一行后,执行OtherAction方法,然后在该代码的最后一行它引发此异常:
视图“索引”或它的主人没有被发现或没有视图发动机 支持搜索位置。以下位置是 搜寻:
〜/查看/控制器/的Index.aspx
〜/查看/控制器/ Index.ascx
〜/查看/共享/的Index.aspx
〜/查看/共享/ Index.ascx
〜/查看/控制器/ Index.cshtml
〜/查看/控制器/ Index.vbhtml
〜/查看/共享/ Index.cshtml
〜/查看/共享/ Index.vbhtml
这究竟是为什么以及如何解决呢?