System.Collections.Generic.Ienumerable

Asked

Viewed 271 times

0

Help, guys!

I’ve tried to do everything, already includes "using System.Linq"and nothing. Anyone knows? 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);
        }

    }
}

Cademeumedico.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; }
    }
}

1 answer

1


Opa, analyzing the image you sent before editing the message, the problem occurs because you return a list to View, correct is you iterate on the list with a foreach, as in the example below:

<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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.