I'm using attribute routing in MVC 5, but I've began to notice a bit of a pain point. I have a situation where I want to subclass a controller because all the actions are going to do the same thing. However, I will obviously need to use different routes for the subclasses' actions. Right now, I'm doing something akin to:
public class FooController : Controller
{
[Route("foo", Name = "Foo")]
public virtual ActionResult Foo()
{
...
return View();
}
}
public class BarController : FooController
{
[Route("bar", Name = "Bar")]
public override ActionResult Foo()
{
return base.Foo();
}
}
This just seems awful to me. I'm not repeating the code for the actual action method (which in some cases is quite a lot), at least, but this just feels wrong to me. Also, in situations where the base action method definition changes for some reason, this becomes a bit of a maintenance nightmare. Is there some way I'm missing, in general, to change the attribute without having to override the method? Perhaps, something attribute routing-specific. Or am I just kind of out of luck?