I am trying to show a dropdownlist, of an entity that I have in my model, for that I used entityframework database first.
Code in my view:
<div class="col-md-10">
@Html.DropDownListFor(x => x.Nivel.NivelID, new SelectList(Model.ListNivel,"NivelID","Nivel1"), htmlAttributes : new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Nivel.NivelID, "", new { @class = "text-danger" })
</div>
My model:
public partial class Nivel
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Nivel()
{
this.Detalle_Curso = new HashSet<Detalle_Curso>();
this.Seccion = new HashSet<Seccion>();
}
public int NivelID { get; set; }
public string Nivel1 { get; set; }
public string Descripcion { get; set; }
//public List<Nivel> SelectListItems { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Detalle_Curso> Detalle_Curso { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Seccion> Seccion { get; set; }
}
As I am trying to reference several models in the same view, create a class to be able to reference them.
public class CursoxGrado
{
public Nivel Nivel {get; set;}
public List<Nivel> ListNivel { get; set; }
public Grado Grado {get; set;}
public Año_Academico Año_Academico { get; set; }
public Curso Curso { get; set; }
}
I just create a List of my entity, but when I execute it sends me the following error.