RouteConfig 的路由注册如下:

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

Razor 代码:

@Html.ActionLink(" 主页", "Index", "Home", new { @class = "fa fa-dashboard" })

这个时候 单击F12 其命中的方法签名是

public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes);

可以看到本该三个参数方法签名中的 controllerName 变成了 object routeValues

这时只需将页面 Razor 代码改为:

@Html.ActionLink(" 主页", "Index", new { controller = "Home" }, new { @class = "fa fa-dashboard" })

即可。

相关文章:

  • 2021-12-18
  • 2022-12-23
  • 2021-12-11
  • 2021-04-18
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-04-19
猜你喜欢
  • 2022-12-23
  • 2021-07-30
  • 2022-01-14
  • 2021-06-13
  • 2022-02-10
  • 2022-01-13
  • 2022-12-23
相关资源
相似解决方案