在RouteConfig-file中,我看到:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);然后在我的控制器中映射到
public Person Get(int id)
{
return _personService.GetPersoonByInszNumber("11111111111");
}现在我想要更改它,使其映射到以下内容:
public Person Get(string inszNumber)
{
return _personService.GetPersoonByInszNumber(inszNumber);
}我该怎么做呢?
发布于 2016-01-27 21:47:54
可以使用attrubute routing完成此操作
[Route("Persons/Get/{id:int}")]
public Person Get(int id)
{
....
}
[Route("Persons/Get/{inszNumber}")]
public Person Get(string inszNumber)
{
....
}只需添加适当的属性(这里我假设您的控制器名称是PersonsController。在其他情况下,适当地将其更改为您的操作。
还要确保在默认路由声明之前的RegisterRoutes方法中有这行代码:
routes.MapMvcAttributeRoutes();https://stackoverflow.com/questions/35038655
复制相似问题