【问题标题】:HTML.ActionLink returns nullHTML.ActionLink 返回 null
【发布时间】:2013-11-14 10:36:41
【问题描述】:

我有我的查看页面,我有这个代码:

<%: Html.ActionLink("Edit", "Edit", "Admin", new { id = item.Username })%>

这是我的控制器

public ActionResult Edit(String id)
    {
        String x = id;
    }

但字符串 x 的值为“null”。操作结果在 Controller Admin 中,所以这不是错误。另外我使用 item.Username 在表格中显示结果,它工作正常。

如果我在 View 中尝试这样做

<%: Html.ActionLink("Edit", "Edit", "Admin", new { id = item.Username }, null)%>

我收到错误 404。

有人知道我的错误在哪里吗?

【问题讨论】:

  • 您在 Global.asax 中检查过路线吗?
  • 是的,一切正常。

标签: c# asp.net-mvc visual-studio-2010 html.actionlink


【解决方案1】:

尝试过的 Url.Action

<a href="@(Url.Action("Edit", "Action", new { id = item.Username }))"></a>

【讨论】:

    【解决方案2】:

    您可以使用以下 ActionLink Helper 的重载:

    <%: Html.ActionLink("Edit", "Edit", new { Controller = "Admin", Action = "Edit", id = item.Username  } )%>
    

    这应该可以完成工作。

    【讨论】:

    • 此代码将我发送到页面 ../Admin/Edit/item.Username。你能告诉我如何为此创建代码视图吗?
    【解决方案3】:

    尝试另一个重载:

    <%: Html.ActionLink("Edit", "Edit", new RouteValueDictionary() {{"id",item.Username}}) %>
    

    点击here了解更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 2020-06-19
      相关资源
      最近更新 更多