【问题标题】:Routes values not passing in Html.ActionLink attribute in MVC 4路由值未在 MVC 4 中传入 Html.ActionLink 属性
【发布时间】:2014-08-23 13:17:34
【问题描述】:

我想将一个像字符串一样的 id 传递给我的操作方法,我正在这样做

 <li>@Html.ActionLink("Nokia Lumia Series", "Mobiles", "Products", new { id = "Lumia" })

这是我的操作方法

public ActionResult Mobiles(string name)
        {
            return View();
        }

但它不会执行该操作,并且此 url 显示在浏览器选项卡中

http://mymobiles.com/Home/Mobiles?Length=8

我在这里做错了什么??

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 razor html-helper


    【解决方案1】:

    您使用了不正确的 ActionLink 重载。你应该使用this重载:

    public static MvcHtmlString ActionLink(
        this HtmlHelper htmlHelper,
        string linkText,
        string actionName,
        string controllerName,
        Object routeValues,
        Object htmlAttributes
    )
    

    那么你的代码就变成了,我也改了你的参数名,让它更清楚:

    @Html.ActionLink("Nokia Lumia Series", "Mobiles", "Products", new { name = "Lumia" }, null)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      • 2016-07-16
      相关资源
      最近更新 更多