如何在Html.ActionLink asp.net MVC中调用Route Name?

ido*_*how 8 routes html.actionlink

我有这条路

routes.MapRoute(
    "ViewGames",     // Route name
    "psp/{controller}/{action}",                           // URL with parameters
    new { controller = "Games"}  // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)

我用<%= Html.ActionLink("God of War", "godofwar", "Games")%>所有,虽然它给了我一个链接,这样somesite.com/psp/games/godofwar/,但其他环节也成为像例如我的HomeController成为这个somesite.com/psp/home/about/

怎么可以调用routename所以其他人不会有ViewGames路由?

我不想尝试这个<a href="/psp/games/godofwar/">不好的...

fel*_*xmm 25

您使用显式调用路由

<%: Html.RouteLink("link_text", "route_name", route_parameters) %>
Run Code Online (Sandbox Code Playgroud)

Html.RouteLink的所有重载都在这里

  • 你确定吗?RouteLink的第一个参数是锚文本,第二个是路径名...所以:Html.RouteLink("link_text","route_name",route_parameters) (2认同)