I am getting the value from dropdown to controller but when it goes back to View it returns Null
SCREENSHOT OF VIEW:-
SCREENSHOT OF CONTROLLER:-
public ActionResult Index(int departmentID)
{
ViewBag.dropdowndetail = null;
var strDDLValue = departmentID;
if (strDDLValue == null)
{
return HttpNotFound();
}
else
{
var emp = db.employees.ToList().FirstOrDefault(x=>x.depId==departmentID);
return View(emp);
}
}
POST
the form data and then return to the View, the dropdown data isnull
? If so, this is because you ALSO need to populateViewBag.dropdowndetail
on thePOST
action before you return the View. ViewBag only lasts for the current request. – scgoughPOST
the form – scgough