【问题标题】:How to get URL of Default Action in ASP.NET MVC如何在 ASP.NET MVC 中获取默认操作的 URL
【发布时间】:2016-05-10 16:04:12
【问题描述】:

我想获取默认控制器的默认操作方法链接的 URL,这样如果我在路由配置中更改默认控制器和操作,那么也应该在视图中更新。 例如

  Url.Action(defaultAction,DefaultController);
//output should be like
Url.Action("Index","Home")

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    假设默认路由命名为Default(在你的RoutesConfig中):

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

    您可以使用Url.RouteUrl获取网址:

    Url.RouteUrl("Default")
    

    MSDN

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-25
      • 2021-09-18
      • 1970-01-01
      • 2011-01-01
      • 2011-08-01
      • 2013-03-19
      • 2018-04-29
      相关资源
      最近更新 更多