在asp.net mvc(4)中,开箱即用,视图进入Views文件夹,然后由子文件夹中的控制器分组.
控制器进入Controllers文件夹,(View / Edit / Input)模型进入Models文件夹等.
我喜欢视图的组织方式.但是,我不喜欢水平地打破其余的MVC片段.
我的问题是,将视图组织结构保持原样会有什么缺点,但是按控制器(即用例)对其他类进行分组.例如.:
/Home HomeController.cs Indexviewmodel.cs IndexviewmodelBinder.cs /Messages MessagesController.cs MessagesApiController.cs MessagesviewmodelBinder.cs Messageviewmodel.cs MessagesListviewmodel.cs /Views /Home Index.cshtml /Messages MessagesIndex.cshtml MessageDetails.cshtml
解决方法
重要的是View文件的排列,因为它们是在运行时访问的.其他所有内容都被编译到程序集中,因此源文件的物理位置无关紧要.
像你一样,我发现大型项目的默认安排有点尴尬,所以这就是我如何布置我当前的项目:
~/ /Areas /DefaultArea // I always use areas,even when there's only one,because it simplifies things when adding additional areas. /Controllers FooController.cs /Views /Foo FooView.aspx // Yes,I use WebFormView. Just a matter of personal preference FooEdit.aspx FooModels.cs // this file contains my viewmodels
所以基本上,我将我的viewmodel类放在与视图相同的文件夹中,而不是将所有viewmodel放在一起(这使得逻辑意义不大).我很想把我的控制器放在他们的视图文件夹中,但我决定反对它.
到目前为止,我发现我的方法没有任何缺点(现在使用它差不多2年了).