我在MVC项目中使用领域时遇到了一些问题。我能够访问位于该区域下的控制器,但是当它返回到视图(带有模型)时,我会得到一个错误:
没有找到视图'Index‘或其主目录,或者没有视图引擎支持搜索的locations.The,搜索了以下位置:~/Views/MyController/Index.aspx ~/Views/MyController/Index.ascx等等。
下面是MyAreaAreaRegistration:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"MyArea_default",
"MyArea/{controller}/{action}/{id}",
new { controller = "MyController", action = "Index",
id = UrlParameter.Optional });
}Routeconfig:
routes.MapRoute(
name: "Default", // Route name
url: "{controller}/{action}/{id}", // URL with parameters
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "MyApp.Controllers" }
);Global.asax:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
...
RouteConfig.RegisterRoutes(RouteTable.Routes);
}主计长:
return View(myViewModel);我完全被这个困住了。任何帮助都将不胜感激。
发布于 2016-11-11 12:54:38
请更改您的路由配置代码。
routes.MapRoute(
name: "Default", // Route name
url: "{controller}/{action}/{id}", // URL with parameters
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
).DataTokens.Add("area", "MyArea"); ;这将是你的工作。
谢谢。
https://stackoverflow.com/questions/40548333
复制相似问题