MVC3 到区域的默认路由不会搜索区域内的视图
我将默认路由对象设置为区域(也称为“Beheer”)内的控制器(“Beheer”)。
像这样:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Beheer", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
它可以在区域内找到该控制器和操作,但它找不到视图,因为它只在这些位置查找:
~/Views/Beheer/Index.aspx
~/Views/Beheer/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Beheer/Index.cshtml
~/Views/Beheer/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
虽然它应该在这个位置查找:
~/Beheer/Views/Beheer/Index.aspx
我怎样才能让它搜索那里的视图?
我已经尝试过:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { area = "Beheer", controller = "Beheer", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
并且我尝试过这个(使用名称空间):
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Beheer", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { "Areas.Beheer" }
);
但没有任何变化。它在正确的控制器中输入正确的操作,但找不到视图。
I set the default route object to a controller ("Beheer") inside an area (also called "Beheer").
Like this:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Beheer", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
It can find that controller and the action fine inside the Area, but it can not find the view because it only looks in these locations:
~/Views/Beheer/Index.aspx
~/Views/Beheer/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Beheer/Index.cshtml
~/Views/Beheer/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
While it should be looking in this location:
~/Beheer/Views/Beheer/Index.aspx
How can I make it search for the view there?
I already tried:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { area = "Beheer", controller = "Beheer", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
And I tried this (with namespaces):
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Beheer", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { "Areas.Beheer" }
);
But nothing changes. It enters the correct action in the correct controller but can't find the view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在区域注册中添加您的路线。 BeheerAreaRegistration 有一个设置区域名称的属性。
You should add your route in the area registration. BeheerAreaRegistration has a property that sets the area name.
我遇到了这个问题,发现我需要完全限定命名空间,并且在找到正确的视图时遇到问题,直到我终止了 IIS 进程、某种奇怪的缓存或其他可能的东西。
可能会变成
也许你的问题和我的类似 - 也许不是。
I had this problem and found I needed to fully qualify the namespaces and I has issues with it finding the right view until I killed the IIS process, some sort of odd caching or something maybe.
might become
maybe your problem is similar to mine - maybe not.