GetEnumerator Error When Rendering a View

3

I did this just as a test:

@model Operador.MVC.Models.OperadorModel

@{
    ViewBag.Title = "Operador";
}

<table id="tblOperador" class="table table-hover table-striped" border="1" cellspacing="0" style="width: 100%;">
<thead>
    <tr>
        <th>Code</th>
        <th>NameHealth</th>   
        <th>NameDental</th>
        <th>LastUpdateDate</th>  
        <th>LastUpdateLogin</th>     
        <th>Brand Code</th>    
        <th>Brand</th>         
    </tr>
</thead>
<tbody>
@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.NameHealth)
        </td>                                             
        <td>
            @Html.TextBoxFor(modelItem => item.NameDental, new { style = "width: 50px;"})
        </td>
    </tr>
}
</tbody>

When I render it gives me this error:

  

Application Server Error '/'.

     

Compile Error

     

Description: Error compiling a resource needed to service this   solicitation. Review the specific details of the error and modify the   source code properly.

     

Compiler Error Message: CS1579: Foreach Statement Can not   operate on variables of type 'Operador.MVC.Models.OperadorModel' because   'Operator.MVC.Models.OperatorModel' does not contain a public definition   to 'GetEnumerator'

     

Source Error:

     

Line 20: Line 21: Line 22: @foreach (var item in   Model) Line 23: {Line 24:

     

Source file:   c: \ Projects \ VM \ Operator.MVC \ Views \ Operator \ Operator.cshtml Line:   22

     

Show Detailed Output of Compiler:

     

Show Full Build Source:

     

Version Information: Microsoft .NET Framework Version: 4.0.30319;   ASP.NET Version: 04.0.30319.34249

How do I solve the GetEnumerator problem? What should I add?

    
asked by anonymous 08.10.2015 / 18:29

1 answer

5

As the error itself says:

  

Foreach statement can not operate on variables of type 'Operator.MVC.Models.OperatorModel'

Your error is here:

foreach (var item in Model)

Model is a variable of type Operador.MVC.Models.OperadorModel and you can only foreach on variables that implement GetEnumerator() ", such as IEnumerable , List , and the like.

    
08.10.2015 / 18:33