您的位置:首页 > 其它

关于MVC项目目录结构调整的想法

2010-10-11 09:45 239 查看
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 : 网站配置文件
对于小型的项目,这样编程思路不会被切换控制器和视图的操作所打断,内容组织使用上也很方便,大家不妨试试 :)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: