ASP.NET MVC - 放置控制器 &同一文件夹中的关联视图? [英] ASP.NET MVC - putting controller & associated views in the same folder?

查看:24
本文介绍了ASP.NET MVC - 放置控制器 &同一文件夹中的关联视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在为我们的 MVC 应用程序使用默认文件夹结构,并且想知道是否可以将控制器及其相关视图放入同一文件夹中.

We are currently using the default folder structure for our MVC app, and were wondering if it is possible to instead put a Controller and its related views into the same folder.

例如,我们当前结构的一个子集是:

For example, a subset of our current structure is:

 Model folder
   OrderViewModel.cs
 Views folder
   OrderView.aspx
   OrderGrid.ascx
   OrderHeader.ascx
 Controllers folder
   OrderController.cs

期望:

 Order folder
   OrderController.cs       
   OrderGrid.ascx
   OrderHeader.ascx
   OrderViewModel.cs
   OrderView.aspx

我们有数百个动作/视图,而它们目前被分组到太少的控制器中.这部分是因为在视图及其相关类之间来回切换时,在项目中导航变得很痛苦.上述解决方案将允许专注于一个控制器操作的开发人员轻松访问所有这些操作.

We have hundreds of actions/views, and they're currently grouped into too few controllers. This is partly because it becomes a pain to navigate around the project when flipping back and forth between a view and its related classes. The above solution would allow a developer focusing on one controller action to have all of them easily accessible.

我想区域也可以帮助解决这个问题,但我们必须制作大约 100 个区域(每组密切相关的屏幕一个)才能从我团队的 POV 中获得有用的信息.

I guess Areas could help with this too, but we'd have to make ~100 areas (one per set of closely related screens) to make this useful from my team's POV.

推荐答案

默认的控制器工厂使用反射来查找所有从 Controller 派生的类,所以无论你把它们放在哪个文件夹中,作为只要它们是公共的并且从 Controller 派生出来,它就可以工作.但是恕我直言,将视图和控制器混合到同一个文件夹中并不是一个好主意.如果是组织控制器的问题,为什么不在 Controllers 文件夹中创建子文件夹?

The default controller factory uses reflection to find all classes that derive from Controller, so no matter in which folder you put them, as long as they are public and derive from Controller it will work. But IMHO mixing views and controllers into the same folder is not a good idea. If it is a matter of organizing your controllers why not create subfolders in the Controllers folder?

这篇关于ASP.NET MVC - 放置控制器 &同一文件夹中的关联视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆