I have the following entities:

 public class Entidad
    {
        [Key]
        public int Id { get; set; }
        public string Nombre { get; set; }

        public virtual ICollection<Propiedad> Propiedades { get; set; }
}




 public class Propiedad
    {
        [Key]
        public int Id { get; set; }

        public virtual Entidad Entidad { get; set; }

        public string Codigo { get; set; }
        public string Nombre { get; set; }
        public string TipoDeDatos { get; set; }
    }

And I have this controller action

    public ActionResult Create()
    {
        ViewBag.Entidad = new SelectList(db.Entidades);
        return View();
    }

and on my view:

<div class="form-group">
    @Html.LabelFor(model => model.Entidad, new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.DropDownListFor(model => model.Entidad.Id, new SelectList(ViewBag.Entidad, "id", "nombre", 0), "Seleccionar", new { @class = "form-control" })
    </div>
</div>

However I get this error: DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'id'.

I also tried with Camel Case Id but still the same.

Related posts

Recent Viewed