飞秋_关于MVC项目目录结构调整的建议

飞秋_关于MVC项目目录结构调整的建议

MVC项目的默认目录结构:
    Scripts               : js 文件 飞秋
    Content               : css, image 等文件
    Controllers           : 控制器目录
        HomeController.cs : Home 控制器,对应的视图在Views/Home/目录下
        ProductController.cs : Product 控制器,对应的视图在Views/Product目录下
    Models                : 模型目录,里面放实体类代码
    Views                 : 视图目录
        Home              : Home视图目录,对应HomeController.cs
            Index.aspx    : Home/Index视图,对应HomeController.Index方法
            Create.aspx   : Home/Create视图,对应HomeController.Create方法
        Product           : Product视图目录,对应ProductController.cs
            Index.aspx    : Product/Index视图,对应ProductController.Index方法
            Create.aspx   : Product/Create视图,对应ProductController.Create方法
        Shared            : 共享的一些视图,用户控件,masterpage等可以放在这
        web.config        : 该文件禁止了直接访问该目录下的视图。所有的请求都由路由以及控制器控制
    Default.aspx          : 默认页
    global.asax           : 在该文件中写了路由规则
    web.config            : 飞秋 网站配置文件

飞秋

我的想法:
    (1)script、css以及image经常是组合在一起使用的(如jqGrid),强行分成两个目录很不方便,建议合并
    (2)在实际使用中查找Controller和对应的视图有点麻烦,必须在两个不同的目录下查找。
        ·虽说控制器和视图是低耦合的,但毕竟还是有千丝万缕的关系
        ·将控制器和视图分在两个目录存放,编程过程中经常会有思维中断的现象出现
        ·不像webform那样,直接双击asp页面的控件就可以跳到cs页面,思维上和操作上都很自然
        飞秋 我建议,对于小型项目可以将controller文件都放到对应的视图文件夹中。

飞秋[www.freeeim.com]
故调整后的目录如:
    Content               : css, image,js 等文件
    Models                : 模型目录,里面放实体类代码
    Views                 : 视图目录
        Home              : Home视图目录,对应HomeController.cs
            HomeController.cs : Home 控制器,对应的视图在Views/Home/目录下
            Index.aspx    : Home/Index视图,对应HomeController.Index方法
            Create.aspx   : Home/Create视图,对应HomeController.Create方法
        Product           : Product视图目录,对应ProductController.cs
            ProductController.cs : Product 控制器,对应的视图在Views/Product目录下
            Index.aspx    : Product/Index视图,对应ProductController.Index方法
            Create.aspx   : Product/Create视图,对应ProductController.Create方法
        Shared            : 共享的一些视图,用户控件,masterpage等可以放在这
        web.config        : 该文件禁止了直接访问该目录下的视图。所有的请求都由路由以及控制器控制
    Default.aspx          : 默认页
    global.asax           : 在该文件中写了路由规则
    web.config            : 网站配置文件

对于小型的项目,这样编程思路不会被切换控制器和视图的操作所打断,内容组织使用上也很方便,大家不妨试试 :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在 Python 中,MVC 项目目录结构可以按照以下方式组织: ``` project_name/ ├── app/ │ ├── __init__.py │ ├── controllers/ │ │ ├── __init__.py │ │ ├── home_controller.py │ │ └── user_controller.py │ ├── models/ │ │ ├── __init__.py │ │ ├── home_model.py │ │ └── user_model.py │ └── views/ │ ├── __init__.py │ ├── home/ │ │ ├── index.html │ │ └── about.html │ ├── user/ │ │ ├── login.html │ │ └── register.html │ └── shared/ │ ├── layout.html │ └── navbar.html ├── config/ │ ├── __init__.py │ ├── app_config.py │ ├── database_config.py │ └── routes.py ├── static/ │ ├── css/ │ ├── js/ │ └── img/ ├── tests/ │ ├── __init__.py │ ├── test_home_controller.py │ ├── test_user_controller.py │ ├── test_home_model.py │ └── test_user_model.py ├── requirements.txt ├── run.py └── README.md ``` 其中,`app` 文件夹包含了 MVC 中的三个部分:`controllers`(控制器)、`models`(模型)和 `views`(视图);`config` 文件夹包含了项目的配置文件;`static` 文件夹包含了静态文件,如 CSS、JavaScript 和图像;`tests` 文件夹包含了项目的单元测试;`requirements.txt` 文件包含了项目的依赖项;`run.py` 文件是项目的入口文件;`README.md` 是项目的说明文档。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值