码迷,mamicode.com
首页 > Web开发 > 详细

记录:MVC5 区域(Areas)属性路由应用

时间:2017-09-26 14:57:27      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:col   tin   class   news   应用   url   ret   index   res   

1、删除 xxxAreaRegistration.cs文件

2、HomeController

 1     [RouteArea("Mobile")]
 2     [RoutePrefix("Home")]
 3     [Route("{action = Index}")]
 4     public class HomeController : Controller
 5     {
 6         // GET: Mobile/Home
 7         [Route]
 8         [Route("Index")]
 9         public ActionResult Index()
10         {
11             var dtIndexBN = CSA_BLL.Ad.Ad.GetAdByAdKindCode("01");
12             ViewBag.BNList = dtIndexBN;
13 
14             return View();
15         }
16     }

2、JoinController

 1     [RouteArea("Mobile")]
 2     [RoutePrefix("Join")]
 3     [Route("{action = Index}")]
 4     [Route("{controller=Join}/{action= Index}/{code}")]
 5     public class JoinController : Controller
 6     {
 7         private CSA_BLL.Entity.JsonMessage jm = new CSA_BLL.Entity.JsonMessage();
 8         // GET: Mobile/Join
 9         [Route]
10         [Route("Index")]
11         [Route("Index/{code}",Name = "JoinCode")]
12         public ActionResult Index()
13         {
14             ViewBag.CurKindName = CSA_BLL.Article.Kind.getKindName("07");
15             ViewBag.CurKindList = CSA_BLL.Article.Kind.getKind("07", 2);
16             ViewBag.NewList = CSA_BLL.Article.Article.getArticle("07", 0, "Bs_NewsKindCode asc");
17             return View();
18         }
19     }

3、生成链接

@Url.RouteUrl("JoinCode", new {action="Index",controller="Join",code=item["code"]})

记录:MVC5 区域(Areas)属性路由应用

标签:col   tin   class   news   应用   url   ret   index   res   

原文地址:http://www.cnblogs.com/qishidz/p/7596421.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!