zoukankan      html  css  js  c++  java
  • RouteArea中AreaPrefix(Area 前缀)的使用

     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>

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

  • 相关阅读:
    中文和英文
    文件字符流
    Java IO File
    关于整数拆分的递归法与母函数法
    图论·Dijkstra·HDU2066
    图论·Floyd算法·HDU2544&1874 (伪)2066
    关于 图论·并查集·HDU1232&1856
    Power of Cryptography
    Y2K Accounting Bug
    整数划分
  • 原文地址:https://www.cnblogs.com/baobaodong/p/4773313.html
Copyright © 2011-2022 走看看