Asp.net mvc 5 MVC5路由将URL更改为inclide class name属性而不是ID,并显示操作

Asp.net mvc 5 MVC5路由将URL更改为inclide class name属性而不是ID,并显示操作,asp.net-mvc-5,asp.net-mvc-routing,Asp.net Mvc 5,Asp.net Mvc Routing,我的默认路由配置声明如下: routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 如果我有一个团队控制器,我想向团队展示URL: http://exam

我的默认路由配置声明如下:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
如果我有一个团队控制器,我想向团队展示URL:

http://example.com/Teams/Show/1
在不影响其余路线的情况下,是否有一种配置方法,使其仅显示为:

http://example.com/Teams/Arizona

对。一种方法是使用属性路由

在您的
RouteConfig
或同等产品中:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapMvcAttributeRoutes();
    }
}
在您感兴趣的控制人中:

[Route("Teams/{teamName}")]
public ActionResult ShowTeam(string teamName)
{
     var teamInfoViewModel = Service.GetViewModel(teamName);
     return View(teamInfoViewModel);
}

我将拥有模型中的class属性,是否可以在document.ready上添加URL?我认为这将在document.ready…window.location.href=URL+“#”+class attr…@Jay Me-alegro de-poder-ayudar a中起作用