chinna_82
chinna_82

Reputation: 6403

Asp.Net - MVC - System.Collections.Generic.IEnumerable

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>

Upvotes: 2

Views: 3354

Answers (2)

ActiveDan
ActiveDan

Reputation: 349

You've tried to set the id property of your actionlink to Model.Idx, but your Model is an IEnumerable of VOC_CUSTODIAN objects. You needed to use the Idx value of the collection's current enumerator. You just need to change "Model" to "item", just like every other html control in your loop:

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

Upvotes: 1

McGarnagle
McGarnagle

Reputation: 102763

You're still referencing the item enumerator. So it needs to be item instead of Model:

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

Upvotes: 2

Related Questions