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.

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

1 Answers1

3

Based on the notes found here: http://attributerouting.net/#route-prefixes the IsAbsoluteUrl flag is designed to ignore the RoutePrefix defined on the Controller. For example:

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

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

So, using the 'standard' AttributeRouting (for lack of a better name), the following routes should map to your Index() method:

  • / (1)
  • /MyApp/Index (2)

The new Attribute based routing in MVC5 has similar functionality (being based on the former), just slightly different syntax (see 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() {
        ...
    }
}

The tilde ~ seems to be equivalent of IsAbsoluteUrl.

thecodefish
  • 388
  • 2
  • 13