c# - HTML ActionLink 未显示

标签 c# asp.net asp.net-mvc

我正在显示一个包含用户名列表的小表格,我希望每个用户名旁边都有一个 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/

相关文章:

c# - 从集合中删除/跳过项目的最佳方法是什么

c# - LINQ 到实体 : Orderby statement involving extension method

asp.net-mvc - 多个 Asp.Net 项目之间的共享代码

javascript - 脚本代码不在 foreach 循环内运行?

c# - 发送游戏 key

c# - 在 webapi 方法中获取主机名

c# - SQLite 是否与 Entity Framework 配合良好?

asp.net - 自定义字体不适用于 IIS 7 上托管的 Firefox 8 上的本地网站和实时网站

c# - Xamarin 形成包含适用于 Android 和 iOS 的图像的共享项目

asp.net - 将 MVC 应用程序部署到 Azure 后无法加载 NewtonSoft.JSON