标签:
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