Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6941955
  • 博文数量: 701
  • 博客积分: 10821
  • 博客等级: 上将
  • 技术积分: 12021
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-02 10:41
个人简介

中科院架构师,专注企业数字化各个方面,MES/ERP/CRM/OA、物联网、传感器、大数据、ML、AI、云计算openstack、Linux、SpringCloud。

文章分类

全部博文(701)

分类: Web开发

2011-04-15 18:00:55

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文件都放到对应的视图文件夹中。

故调整后的目录如:
    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            : 网站配置文件

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

阅读(7519) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~