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

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

问题描述

我们当前正在为MVC应用程序使用默认文件夹结构,并且想知道是否有可能将Controller及其相关视图放到同一文件夹中.

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.

我想Areas也可以帮上忙,但是我们必须制作约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天全站免登陆