nia*_*iao 3 directory-structure asp.net-mvc-4
我正在使用ASP.NET MVC 4开发一个Web应用程序,我想以下列方式组织我的控制器和视图:
/Controller
/Admin
/LessonController.cs
/ExerciseController.cs
HomeController.cs
/Views
/Admin
/Lesson
/Index.cshtml
/Home
/Index.cshtml
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码来注册路由,但它不起作用:
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 }
);
}
Run Code Online (Sandbox Code Playgroud)
你有什么建议吗?
Dar*_*rov 10
你可以使用areas它们,它们是为这种类型的隔离设计的,它会为你提供一些开箱即用的分离:
/Areas
/Admin
/Controllers
/LessonController.cs
/ExerciseController.cs
/Views
/Lesson
/Index.cshtml
/Exercise
/Index.cshtml
/Controllers
/HomeController.cs
/Views
/Home
/Index.cshtml
Run Code Online (Sandbox Code Playgroud)
如果您不想遵循ASP.NET MVC支持的标准约定,则必须执行此操作write and register a custom view engine.
| 归档时间: |
|
| 查看次数: |
12888 次 |
| 最近记录: |