您的位置:首页 > 编程语言 > ASP

asp.net mvc 多级目录结构

2014-11-21 10:57 543 查看
ikmb@163.com

ASP.NET MVC默认的文件组织和URL访问都是一级,我们通常要将一个功能模块组织到一个目录下。方法是:
1、文件组织



分别在Controllers和Views文件夹下建议CaiGou文件夹,然后将CaiGou模块的CV将到对应文件夹下

2、URL Routing

[c-sharp] view plaincopy

//采购部分路由

routes.MapRoute(

"CaiGou", // 路由名称

"CaiGou/{controller}/{action}/{id}", // 带有参数的 URL

new { controller = "AddCaiGou", action = "Index", id = UrlParameter.Optional } // 参数默认值

);

//默认路由

routes.MapRoute(

"Default", // 路由名称

"{controller}/{action}/{id}", // 带有参数的 URL

new { controller = "Home", action = "Index", id = UrlParameter.Optional }

);

3、Contorller调用View

[c-sharp] view plaincopy

public ActionResult Index()

{

return View("~/Views/CaiGou/AddCaiGou/Index.aspx");

}

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: