简体   繁体   English

ASP.NET MVC2路由/文件夹结构

[英]ASP.NET MVC2 Routing / Folder structure

In ASP.NET MVC2, 在ASP.NET MVC2中,

How do I change routing/folder structure so I can have 如何更改路由/文件夹结构,以便

  • Views\\FOLDER\\Account\\ChangePass.aspx 查看\\文件夹\\帐户\\ ChangePass.aspx

Rather than: 而不是:

  • Views\\Account\\ChangePass.aspx 查看\\帐户\\ ChangePass.aspx

I don't actually want to do it for the account, but I'd like to structure things like that, eg 我实际上不想为该帐户执行此操作,但是我想构建类似的内容,例如

SO I can have two different views like: 所以我可以有两种不同的看法,例如:

  • Views\\Categories\\ 意见\\类别\\

  • Views\\Admin\\Categories\\ 视图\\管理\\类别\\

These would display completely differently. 这些将完全不同地显示。

All I want to do is to be able to create my own subfolders to push the views into, not a seperate folder for each different controller............................................................... 我要做的就是能够创建自己的子文件夹以将视图推入,而不是为每个不同的控制器创建一个单独的文件夹............. .........................................

Sounds to me like you need to look into using areas... Have a look at this article for more info: 在我看来,您需要研究使用领域...请查看本文以了解更多信息:

Walkthrough: Organizing an ASP.NET MVC Application using Areas 演练:使用区域组织ASP.NET MVC应用程序

Excerpt: 摘抄:

However, some applications can have a large number of controllers, and each controller can be associated with several views. 但是,某些应用程序可能具有大量的控制器,并且每个控制器可以与多个视图关联。 For these types of applications, the default ASP.NET MVC project structure can become unwieldy. 对于这些类型的应用程序,默认的ASP.NET MVC项目结构可能变得笨拙。

To accommodate large projects, ASP.NET MVC lets you partition Web applications into smaller units that are referred to as areas. 为了容纳大型项目,ASP.NET MVC允许您将Web应用程序划分为较小的单元,称为区域。 Areas provide a way to separate a large MVC Web application into smaller functional groupings. 区域提供了一种将大型MVC Web应用程序划分为较小功能组的方法。 An area is effectively an MVC structure inside an application. 区域实际上是应用程序内部的MVC结构。 An application could contain several MVC structures (areas). 一个应用程序可能包含几个MVC结构(区域)。

HTHs, HTHS,
Charles 查尔斯

Go with the asp.net MVC convention for view location; 使用asp.net MVC约定查看位置; if you want to have different url paths you need to look at creating your own routes, other than the default single route given to you. 如果您要使用其他网址路径,则需要查看创建自己的路由,而不是提供给您的默认单个路由。 (See this primer .) (请参阅本入门书 。)

Here's an example of a route that you might add in your Global.asax to have the desired result but you'll have to map this route to a controller action appropriately. 这是一个路由示例,您可以将其添加到Global.asax中以获得所需的结果,但必须将该路由适当地映射到控制器操作。 Really, your need to decide on the pattern to meet the need of your app... 确实,您需要确定模式以满足您的应用程序需求。

        routes.MapRoute(
            "FolderRoute",                                             
            "{controller}/{folder}/{action}/{id}",                     
            new { controller = "Home", folder = "yourFolderDefault", action = "Index", id = "" }
        );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM