asp.net mvc 多级目录结构

ikmb@163.com

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

 

2、URL Routing

 

[c-sharp]  view plain copy
 
  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 plain copy
 
  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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值