i have a dropdownlist getting data from data base
it contains 4 data :
my controller :
public ActionResult Index()
{
ViewBag.Postes = _db.Postes.ToList();
return View();
}
[HttpPost]
public ActionResult Index( Poste poste,string num_cin="R346399")
{
if (ModelState.IsValid)
{
if (poste.Id == 3)
{
return RedirectToAction("Inscription", "Candidat");
}
return View(poste);
}
}
my view
@Html.DropDownListFor(model => model.Id,
new SelectList(ViewBag.Postes, "Id", "intitule_poste"),"choisir le poste")
the problem that if i choose a value from dropdownlist that !=3 it's give me an error "that items must be not null "
model => model.Id