命名空间相当于ASP.NET MVC?

编程入门 行业动态 更新时间:2024-10-19 22:37:07
本文介绍了命名空间相当于ASP.NET MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在铁轨我可以为了封装给定的名称里面的观点(或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?

本文发布于:2023-11-03 15:27:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555448.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空间   ASP   MVC   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!