1

I am trying to get attribute routing in MVC5 to let me inherit the routes from a base controller. Example:

public abstract class BaseController: Controller
{
    [Route("")]
    public virtual ActionResult Index()

    [Route("edit/{id}")]
    public virtual ActionResult Edit(TKey id)

    //etc
}

[RoutePrefix("people")]
public class PersonController : BaseController
{
    //etc
}

Then obviously I should have /people for the Index page, /people/edit/1 for the Edit page etc. However, it seems like this is not supported or I just don't know what I'm doing. Is there a way to get this working the way I want?

Matt
  • 6,787
  • 11
  • 65
  • 112
  • 1
    Route attributes cannot be inherited. See: http://stackoverflow.com/questions/19989023/net-webapi-attribute-routing-and-inheritance – esmoore68 May 02 '14 at 15:01
  • +1 for the link. Thanks, @esmoore68. Bad luck; let's hope they allow such a scenario in a future version. – Matt May 02 '14 at 15:14
  • @esmoore68, add your comment as an answer and I will mark it as the correct answer – Matt May 08 '14 at 01:35

1 Answers1

1

According to this: .NET WebAPI Attribute Routing and inheritance, route attribute cannot be inherited. Apparently, MVC 5.2 will have support for doing this through IDirectRouteProvider.

Community
  • 1
  • 1
esmoore68
  • 1,276
  • 1
  • 8
  • 16