MVC默认路由问题

时间:2018-05-03 14:56:12

标签: asp.net-mvc razor routing

我将家庭控制器作为默认页面,具有以下路由

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );

    routes.MapRoute(
      name: "Home",
      url: "{Home}/{Index}/{lang}",
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  );
}

但是,当我转到其他页面并尝试从视图下面的超链接

<a  href="@Url.Action("Index", "Home", new {id = id } )"></a>

它只是重定向到家庭控制器,其中包含以下网址http://localhost:57457?id=1160,但我希望它为http://localhost:57457/Home?id=1160

0 个答案:

没有答案