Saturday 18 May 2013

ASP.NET MVC4 - How to fix error "The name 'modelItem' does not exist in the current context"


Watch on YouTube:
Replace 
 <table>
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
        </tr>
        @foreach (var item in Model.Users)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem = item.FirstName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem = item.LastName)
                </td>
            </tr>
        }
    </table>

with

    <table>
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
        </tr>
        @foreach (var item in Model.Users)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.FirstName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LastName)
                </td>
            </tr>
        }
    </table>

1 comment: