2013-11-05 24 views

回答

3

基於此處找到的註釋:http://attributerouting.net/#route-prefixesIsAbsoluteUrl標誌旨在忽略Controller上定義的RoutePrefix。例如:

[RoutePrefix("MyApp")] 
public class MyController : Controller { 

    [GET("", IsAbsoluteUrl = true)] //1 
    [GET("Index")] //2 
    public ActionResult Index() { 
     ... 
    } 
} 

因此,使用 '標準' AttributeRouting(缺乏一個更好的名字)下面的路線應該映射到Index()方法:

  • /(1)
  • /MyApp的/索引(2)

在MVC5新屬性的路由具有類似的功能(是基於前),只要稍微不同的語法(見http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx

[RoutePrefix("MyApp")] 
public class MyController : Controller { 

    [Route("~/")] //1 
    [Route("Index")] //2 
    public ActionResult Index() { 
     ... 
    } 
} 

的波浪~似乎是等同的IsAbsoluteUrl