gpt4 book ai didi

asp.net-mvc - Asp.Net - MVC - System.Collections.Generic.IEnumerable

转载 作者:行者123 更新时间:2023-12-04 05:43:00 25 4
gpt4 key购买 nike

我是 Asp.net 和 MVC 的新手。我试图做编辑功能,但它给我一个错误。
CS1061:“System.Collections.Generic.IEnumerable”不包含“Idx”的定义,并且找不到接受“System.Collections.Generic.IEnumerable”类型的第一个参数的扩展方法“Idx”(您是否缺少使用指令还是程序集引用?)

代码

@model IEnumerable<SealManagementPortal_3._0.Models.VOC_CUSTODIAN>

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
StaffID
</th>
<th>
Name
</th>
<th>
IC
</th>
<th>
Phone
</th>
<th>
Branch
</th>
<th></th>
</tr>

@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.StaffId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.NRICNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.MobileNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.Branch)
</td>
<td>
@Html.ActionLink("Details", "Details", new { id=Model.Idx }) // error here
</td>

</tr>
}

</table>

最佳答案

您仍在引用项目枚举器。所以它需要是 item 而不是 Model:

 @Html.ActionLink("Details", "Details", new { id = item.Idx })

关于asp.net-mvc - Asp.Net - MVC - System.Collections.Generic.IEnumerable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11027379/

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