欢迎光临

木子屋

标题: ASP.NET MVC3为URL添加扩展名示例

作者: dnawo

日期: 2013-03-07 02:33 PM

分类: Web编程

内容: 示例一：ASP.NET MVC3为URL添加扩展名
定义路由：
复制内容到剪贴板 程序代码routes.MapRoute("route1", "", new { controller = "Home", action = "Index" });
routes.MapRoute("route2", "Default.html", new { controller = "Home", action = "Index" });
routes.MapRoute("route3", "{controller}.html", new { action = "Index" });
routes.MapRoute("route4", "{controller}/{id}.html", new { action = "Index" });
routes.MapRoute("route5", "{controller}/{action}.html");
routes.MapRoute("route6", "{controller}/{action}/{id}.html");
输出链接：
复制内容到剪贴板 程序代码@Html.RouteLink("route1", "route1")
@Html.RouteLink("route2", "route2")
@Html.RouteLink("route3", "route3", new { controller = "News" })
@Html.RouteLink("route4", "route4", new { controller = "News", id = 1 })
@Html.RouteLink("route5", "route5", new { controller = "News", action = "Sport" })
@Html.RouteLink("route6", "route6", new { controller = "News", action = "Sport", id = 1 })
页面链接：
引用内容http://localhost/
http://localhost/Default.html
http://localhost/News.html
http://localhost/News/1.html
http://localhost/News/Sport.html
http://localhost/News/Sport/1.html
效果是达到了，但总感觉Html.RouteLink参数太长了，再做下简化。
示例二：简化Html.RouteLink参数
定义路由：
复制内容到剪贴板 程序代码routes.MapRoute("route1", "", new { controller = "Home", action = "Index" });
routes.MapRoute("route2", "Default.html", new { controller = "Home", action = "Index" });
routes.MapRoute("route3", "News.html", new { controller = "News", action = "Index" });
routes.MapRoute("route4", "News/{id}.html", new { controller = "News", action = "Index" });
routes.MapRoute("route5", "News/Sport.html", new { controller = "News", action = "Sport" });
routes.MapRoute("route6", "News/Sport/{id}.html", new { controller = "News", action = "Sport" });
输出链接：
复制内容到剪贴板 程序代码@Html.RouteLink("route1", "route1")
@Html.RouteLink("route2", "route2")
@Html.RouteLink("route3", "route3")
@Html.RouteLink("route4", "route4", new { id = 1 })
@Html.RouteLink("route5", "route5")
@Html.RouteLink("route6", "route6", new { id = 1 })
页面链接：
引用内容http://localhost/
http://localhost/Default.html
http://localhost/News.html
http://localhost/News/1.html
http://localhost/News/Sport.html
http://localhost/News/Sport/1.html

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.781 ms

返回

标题: ASP.NET MVC3为URL添加扩展名示例

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.781 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.813 ms

返回