i've just started using AttributeRouting with my ASP.NET MVC3 application. I started out with -no- controllers at all. (New Empty MVC3 Application)
I then made an area. (called: Documentation
)
I then added a controller (called: DocumentationController
)
I've then done this..
[RouteArea("Documentation")]
public class DocumentationController : Controller
{
[GET("Index")]
public ActionResult Index()
{
return View();
}
}
And the following route, works: /documentation/index
but how can I make these two routes, work?
1 - /
<-- (default route / no specific route specified)
2 - /documentation
<-- no 'index' subroute section added.
Can this be done with AttributeRouting?
I know how to do this with the default ASP.NET MVC3 structure, etc. What I'm trying to do is figure this out via AttributeRouting instead.
I assume you want the "/" and "/documentation" to map to DocumentationController.Index, yes? If so, do this:
[RouteArea("Documentation")]
public class DocumentationController : Controller
{
[GET("Index", Order = 1)] // will handle "/documentation/index"
[GET("")] // will handle "/documentation"
[GET("", IsAbsoluteUrl = true)] // will handle "/"
public ActionResult Index()
{
return View();
}
}
A bit of explanation:
Hope this helps. If my initial assumption of what you're trying to do is incorrect, please comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With