在铁轨我可以为了封装给定的名称里面的观点(或URL preFIX)创建命名空间
In rails I could create a namespace in order to encapsulate views inside a given name ( or URL prefix)
我想要做的就是创建一个命名空间(或地区相信?)那须封装一个给定的名字里面的所有管理员的控制器。
What I want to do is create a namespace (or Area I believe? ) that shall encapsulate all the administrator controllers inside a given name.
例如,我想创建一个管理员命名空间,在这里,每当我去www.myapp/admin/~~V它会得到我用指数法控制器管理,而每当我去www.myapp。 COM /管理/产品应当与索引方法调用产品控制器等,因为我也想限制这些控制器必须登录为一个人。
For example, I want to create an Admin namespace, where whenever I go to www.myapp/admin/ it would get the me the controller admin with the index method, and that whenever I go to www.myapp/admin/products it shall call the product controller with the index method and so on because i also want to limit these controllers to a person that must be logged in as in.
URL和路由明智的,我怎么能完成之前提到的?
URL and routing wise, how can I accomplish the mentioned before?
推荐答案该功能INFACT的是名为区在asp mvc的。
The feature infact is called Areas in asp mvc.
您右键单击在Visual Studio中的项目,然后单击添加区。
You right-click your project in Visual Studio and click add Area.
您现在必须与视图,控制器和一个共享文件夹文件夹的子文件夹。还一个路由添加到项目
You'll now have a sub folder with folders for Views, Controllers and a Shared folder. Also a route is added to the project.
障碍:有一个地方,如果你有这将导致出现问题的情况下的的HomeController 里面的地区之一,因为它会与的HomeController 为网站根路径。史蒂芬·桑德森已定为这在他的书:
Snag: There is a case where it would cause a problem if you have a HomeController inside one of your areas as it will conflict with the HomeController route for the website root. Steven Sanderson has fix for this in his book:
更改默认路由是:
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", // Parameter defaults id = UrlParameter.Optional }, new [] { "MyAppName.Controllers" } // Prioritized namespace );请参阅 MDSN文章的。
视频在Asp领域。
由史蒂芬·桑德森好文章:
更多推荐
命名空间相当于ASP.NET MVC?
发布评论