asp.net-mvc – ASP.NET MVC:围绕控制器分组类

在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年了).

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....