i'm a beginner in MVC
I try to display a viewbag in a drop down list.
Here is what I get in my controller :
public ActionResult TableauPolyvalence()
{
List<Batiments> BatimentList = _context.Batiments.ToList();
ViewBag.BatimentList = new SelectList(BatimentList, "Id_Batiment", "Nom");
return View();
}
Here is my view :
@if (ViewBag.BatimentList != null)
{
@Html.DropDownListFor(model => model.Batiment, (SelectList)ViewBag.BatimentList, "-- Sélectionner le bâtiment --", new { @class = "form-control" })
}
I get the following message error : System.NullReferenceException: 'Object reference not set to an instance of an object.' I tried different way in my View but it doesn't work
Can somoene help me for this please