0

I'm not sure how to convert this AttributeRoute into an MVC5 route.

[GET("", IsAbsoluteUrl = true)] // => main home page.
[GET("Index")]
public ActionResult Index(..) { .. }

The IsAbsoluteUrl is one of the things that is confusing me.

4

1 回答 1

3

根据此处找到的注释:http: //attributerouting.net/#route-prefixesIsAbsoluteUrl标志旨在忽略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-在-asp-net-mvc-5.aspx )

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

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

波浪号~似乎等同于IsAbsoluteUrl.

于 2013-11-05T03:47:57.197 回答