分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

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

发布时间:2023-09-06 01:14责任编辑:彭小芳关键词: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"]})

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

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved