MVC属性的路由和放大器;路线继承 [英] MVC Attribute Routes & Route Inheritance
问题描述
我想获得属性在MVC5路由让我继承一个基本控制器的路由。例如:
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
}
那么显然我应该有 /人
的索引页, /人/编辑/ 1
为编辑网页等,但是,好像这不是支持或我只是不知道我在做什么。有没有办法得到这个工作,我想要的方式?
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?
推荐答案
根据这样的:的 .NET的WebAPI属性路由和继承,路由属性不能被继承。显然,MVC 5.2将通过IDirectRouteProvider这样做支持。
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.
这篇关于MVC属性的路由和放大器;路线继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!