记录:MVC5 区域(Areas)属性路由应用_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 记录:MVC5 区域(Areas)属性路由应用

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

 2017/9/26 14:43:20  qishidz  程序员俱乐部  我要评论(0)
  • 摘要:1、删除xxxAreaRegistration.cs文件2、HomeController1[RouteArea("Mobile")]2[RoutePrefix("Home")]3[Route("{action=Index}")]4publicclassHomeController:Controller5{6//GET:Mobile/Home7[Route]8[Route("Index")]9publicActionResultIndex()10{11vardtIndexBN=CSA_BLL
  • 标签:MVC 应用

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"]})

发表评论
用户名: 匿名