System.Collections.Generic.IEnumerable

0

Help, guys!

I have tried to do everything, already includes "using System.Linq" and nothing. Anybody know? MedicosController

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CadeMeuMedico.Models;
using System.Data.Entity;

namespace CadeMeuMedico.Controllers
{
    public class MedicosController : Controller
    {
        private CadeMeuMedicoBDEntities db = new CadeMeuMedicoBDEntities();
        //
        // GET: /Medicos/

        public ActionResult Index()
        {
            var medicos = db.Medicos.Include(m => m.Cidades).Include(m => m.Especialidades).ToList();
            return View(medicos);
        }

    }
}

CadeMemeMedico.Models

namespace CadeMeuMedico.Models
{
    using System;
    using System.Collections.Generic;

    public partial class Medicos
    {
        public long IDMedico { get; set; }
        public string CRM { get; set; }
        public string Nome { get; set; }
        public string Endereco { get; set; }
        public string Bairro { get; set; }
        public string Email { get; set; }
        public bool AtendePorConvenio { get; set; }
        public bool TemClinica { get; set; }
        public string WebSiteBlog { get; set; }
        public int IDCidade { get; set; }
        public int IDEspecialidade { get; set; }

        public virtual Cidades Cidades { get; set; }
        public virtual Especialidades Especialidades { get; set; }
    }
}
    
asked by anonymous 28.03.2018 / 21:21

1 answer

1

Oops, by analyzing the image you sent before editing the message, the problem occurs because you return a list with View , the correct is you iterate over the list with a foreach , as in the example below: / p>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Nome)
        </th>
        <th>
            Cidade
        </th>
        <th>
            Especialidade
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Nome)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Cidade.Nome)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Especialidade.Nome)
            </td>
            <td>
                @Html.ActionLink("Editar", "Editar", new { id=item.IDMedico }) |
                @Html.ActionLink("Excluir", "Excluir", new { id=item.IDMedico }, new {@class="excluir"})
            </td>
        </tr>
    }
</table>
    
29.03.2018 / 15:29