I am not able to get the value of @Html.DropDownListFor to a controller. I am new to MVC. Here I am adding the code.
Model
public IEnumerable<System.Web.Mvc.SelectListItem> CatID { get; set; }
Controller
public ActionResult Motors()
{
ViewBag.CatID = new SelectList(db1.motors.ToList(), "id", "cat");
return View();
}
View
//(in view DATA is properly loading from database)
@Html.DropDownListFor(m => m.CatID, ViewBag.CatID as SelectList, new { @class = "form-control" })
Controller(Back to controller after post)
[HttpPost]
public ActionResult Motors(MotorInput collection)
{
MotorInput obj = new MotorInput
{
CatID = collection.CatID
};
return View(collection);
}
I am just looking for a way to get the value of @Html.DropDownListFor selected from view to the controller.