'System.Web.Mvc.SelectListItem " enthält keine Eigenschaft mit dem Namen 'id', #2

Habe ich die folgenden Entitäten:

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

Und ich habe diesen controller-action

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

und auf meine Ansicht:

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

Jedoch bekomme ich diesen Fehler:
DataBinding: 'System.Web.Mvc.SelectListItem " enthält keine Eigenschaft mit dem Namen 'id'.

Ich habe auch versucht, mit Camel-Case-Id, aber immer noch das gleiche.

InformationsquelleAutor Sebastián A | 2015-06-11
Schreibe einen Kommentar