码迷,mamicode.com
首页 > 其他好文 > 详细

RouteArea中AreaPrefix(Area 前缀)的使用

时间:2015-08-31 17:20:42      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.Mvc;
 6 
 7 namespace WebApplication6.Controllers
 8 {
 9     [RouteArea("Admin")]
10     [RoutePrefix("testArea")]
11     [Route("{action}")]
12 
13    // 匹配 /dddAdmin/testArea/Index
14     public class MyAreaController : Controller
15     {
16         // GET: MyArea
17         public ActionResult Index()
18         {
19             return View();
20         }
21     }
22 }

这里只用了RouteArea,没有AreaPrefix ,后来我又试了一下加AreaPrefix 的

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.Mvc;
 6 
 7 namespace WebApplication6.Controllers
 8 {
 9     [RouteArea("Admin" ,AreaPrefix="ddd")]
10     [RoutePrefix("testArea")]
11     [Route("{action}")]
12     //  我想当然以为是匹配 /ddd/Admin/testArea/Index
13     public class MyAreaController : Controller
14     {
15         // GET: MyArea
16         public ActionResult Index()
17         {
18             return View();
19         }
20     }
21 }

结过不是想象的那样,因为是第一次用,网上没找到AreaPrefix 的用法,可能是找的方式不对,于是去看了msdn,

以下是对AreaPrefix的解释。

技术分享

看到后半句,我就猜想AreaPrefix 难道与区域名称是相互替代的???

我就试了一下

<a href="/ddd/testArea/Index"> Area测试  </a>

果然能访问到了,比较简单,用于自己备忘罢了

RouteArea中AreaPrefix(Area 前缀)的使用

标签:

原文地址:http://www.cnblogs.com/baobaodong/p/4773313.html

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