【发布时间】:2017-01-29 06:41:18
【问题描述】:
我在不同的命名空间中有两个同名的控制器
-Controllers
--AdminCp
---AccountController.cs
--Cp
---AccountrController.cs
和相同的视图位置结构
-Views
--AdminCp
---Account
----Login.cshtml
--Cp
---Account
----Login.cshtml
我的帐户控制器包含方法登录
public ActionResult Login()
{
return View();
}
我也有自定义RazorViewEngine
public ExtendedRazorViewEngine()
{
ViewLocationFormats = new[]
{
"~/Views/AdminCp/{1}/{0}.cshtml",
"~/Views/Cp/{1}/{0}.cshtml",
"~/Views/{1}/{0}.cshtml",
"~/Views/Layout/{0}.cshtml",
};
}
我的路由使用MvcCodeRouting
routes.MapCodeRoutes(typeof (Controllers.HomeController));
但是当我在Cp namespace 中尝试到动作Login 时,我正在从AdminCp namesapce 获得视图
http://example.com/cp/account/login ---> /views/admincp/account/login.cshtml
我知道我可以通过View() 中的路径定位但是...看起来很难看。
有人可以帮我解决这个问题吗?提前致谢!
【问题讨论】:
-
我看到您创建了两个文件夹:AdminCp 和 Cp。但是 MVC 为此目的内置了功能:Areas。通过使用 Areas MVC 为您整理出这些类型的东西
-
谢谢,我试试
标签: c# asp.net asp.net-mvc asp.net-mvc-4