我正在使用 ASP.NET MVC 4 开发一个 Web 应用程序,我想按以下方式组织我的控制器和视图:
/Controller
/Admin
/LessonController.cs
/ExerciseController.cs
HomeController.cs
/Views
/Admin
/Lesson
/Index.cshtml
/Home
/Index.cshtml
我尝试使用以下代码来注册路由,但它不起作用:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Admin",
url: "Admin/{controller}/action/{id}",
defaults: new { controller = "Lesson", action = "Index", id = UrlParameter.Optional }
);
}
您有什么建议吗?
你可以使用areas http://msdn.microsoft.com/en-us/library/ee671793%28v=vs.100%29.aspx,它们是为这种类型的隔离而设计的,并且会给您某种开箱即用的隔离:
/Areas
/Admin
/Controllers
/LessonController.cs
/ExerciseController.cs
/Views
/Lesson
/Index.cshtml
/Exercise
/Index.cshtml
/Controllers
/HomeController.cs
/Views
/Home
/Index.cshtml
如果您不想遵循 ASP.NET MVC 支持的标准约定,则必须write and register a custom view engine https://stackoverflow.com/a/6184093/29407.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)