C# 另一个默认的MapRoute
在我的网站中,我有以下默认路线:C# 另一个默认的MapRoute,c#,asp.net-mvc,maproute,C#,Asp.net Mvc,Maproute,在我的网站中,我有以下默认路线: routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 当我从主控制器访问索引页时,我得到以下地址: 一切正常,但是,
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
当我从主控制器访问索引页时,我得到以下地址:
一切正常,但是,我想为以下控制器和页面添加另一个默认路由:
对于上面的链接,我希望有以下路线:
不显示“索引”页面名称
如何实现这一点?在RouteConfig中,设置enable以通过属性路由操作:
routes.MapMvcAttributeRoutes();
之后,在操作名称上方添加属性Route:
[Route("Perfil/{id}")]
public ActionResult Index(int? id)
{
return View();
}
在RouteConfig中,设置enable以通过属性路由操作:
routes.MapMvcAttributeRoutes();
之后,在操作名称上方添加属性Route:
[Route("Perfil/{id}")]
public ActionResult Index(int? id)
{
return View();
}
您是否考虑过使用AttributeRouting而不是手动设置它们?您是否考虑过使用AttributeRouting而不是手动设置它们?