【问题标题】:I made a list and want to show it in view in mvc5 but get an error. Here is the code我制作了一个列表并想在 mvc5 中显示它,但出现错误。这是代码
【发布时间】:2021-11-25 03:37:12
【问题描述】:

在这种情况下,有两个表。一个是项目信息,另一个是项目佣金。在项目表中有三列 - 项目 ID、项目名称和价格。在项目佣金表中有佣金 ID、项目 ID 和佣金率三列。 在视图中,我需要显示项目信息表中的项目名称和项目佣金表中的佣金率。 在这种情况下,我使用 linq 来连接两个表。

我创建了一个列表并想在 mvc5 中显示它,但出现错误。代码如下:

@model IEnumerable<FRANCHISEE.Models.FrcItemList>

@{
    ViewBag.Title = "FranchiseeItemList";
}
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ItemName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Roc)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FrcItemId)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.ItemName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Roc)
            </td>

            <td>
                @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
                @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
                @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
            </td>
        </tr>
    }```

【问题讨论】:

  • 错误是什么?
  • 通常有助于告诉我们错误,以及抛出错误的行。

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


【解决方案1】:

我认为这与 ActionLink 有关,在这种情况下,正确的格式在这里:

C# MVC 5 Html.ActionLInk

@Html.ActionLink(customer.Name, "CustomerView", "Customer", new { id = item.PrimaryKey }, null)

【讨论】:

    猜你喜欢
    • 2023-02-10
    • 2018-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    相关资源
    最近更新 更多