首页 > Web开发 > 详细

asp.net mvc 多级目录结构

时间:2014-11-21 12:12:57      阅读:226      评论:0      收藏:0      [点我收藏+]

ikmb@163.com

ASP.NET MVC默认的文件组织和URL访问都是一级,我们通常要将一个功能模块组织到一个目录下。方法是:
1、文件组织
 bubuko.com,布布扣
分别在Controllers和Views文件夹下建议CaiGou文件夹,然后将CaiGou模块的CV将到对应文件夹下

 

2、URL Routing

 

[c-sharp] view plaincopy
 
  1. //采购部分路由  
  2.             routes.MapRoute(  
  3.                 "CaiGou", // 路由名称  
  4.                 "CaiGou/{controller}/{action}/{id}", // 带有参数的 URL  
  5.                 new { controller = "AddCaiGou", action = "Index", id = UrlParameter.Optional } // 参数默认值  
  6.             );  
  7.   
  8.             //默认路由  
  9.             routes.MapRoute(  
  10.                 "Default", // 路由名称  
  11.                 "{controller}/{action}/{id}", // 带有参数的 URL  
  12.                 new { controller = "Home", action = "Index", id = UrlParameter.Optional }  
  13.             );  

 

 

3、Contorller调用View

 

[c-sharp] view plaincopy
 
  1. public ActionResult Index()  
  2.         {  
  3.             return View("~/Views/CaiGou/AddCaiGou/Index.aspx");  
  4.         }  

 

 

4、访问

http://localhost:2325/CaiGou/AddCaiGou

“AddCaiGou”为Controller,看起来有点像Action:)名字没取好
全路径http://localhost:2325/CaiGou/AddCaiGou/Index

REFERENCE FROM : http://blog.csdn.net/ikmb/article/details/5717697

asp.net mvc 多级目录结构

原文:http://www.cnblogs.com/zhangchenliang/p/4112314.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!