每日踩坑 2018-11-26 MVC Razor ActionLink 生成的URL中多生成了一个参数 ?length=n

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" })

即可。

posted @ 2018-11-26 17:43  Aaxuan  阅读(419)  评论(0编辑  收藏  举报