Im new to Asp.net and MVC. Im trying to do edit function but it throws me an error.
CS1061: ‘System.Collections.Generic.IEnumerable’ does not contain a definition for ‘Idx’ and no extension method ‘Idx’ accepting a first argument of type ‘System.Collections.Generic.IEnumerable’ could be found (are you missing a using directive or an assembly reference?)
Code
@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>
You’re still referencing the item enumerator. So it needs to be item instead of Model: