-6ren">
gpt4 book ai didi

c# - HTML ActionLink 未显示

转载 作者:太空宇宙 更新时间:2023-11-03 19:31:27 25 4
gpt4 key购买 nike

我正在显示一个包含用户名列表的小表格,我希望每个用户名旁边都有一个 ActionLink,以便在另一个页面上编辑用户。

这是我的 View 页面:

<%@ Page Title="" Language="C#"
Inherits="System.Web.Mvc.ViewPage<IEnumerable<WebUI.Models.IndexModel>>" %>

<table>
<tr>
<th></th>
<th>Username</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td><% Html.ActionLink("Edit", "Edit", "Employee", new { id = item.UserID }, null); %></td>
<td><%: item.Username %></td>
</tr>
<% } %>
</table>

我在 EmployeeController 中的 Controller 方法:

public ActionResult Index()
{
List<IndexModel> model = new List<IndexModel>();

//load model with data

return View(model);
}

public ActionResult Edit(Guid id)
{
return View();
}

我的模型:

public class IndexModel
{
public Guid UserID { get; set; }
public string Username { get; set; }
}

用户名显示正确,只是链接没有显示。我不确定为什么它不会抛出错误。

我在这里错过了什么?

最佳答案

您的代码中缺少 : 。试试这个:

<td><%: Html.ActionLink("Edit", "Edit", "Employee", new { id = item.UserID }, null) %></td>

编辑:删除了;最后没早点注意到。

关于c# - HTML ActionLink 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4608944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com