There are two models in my application: Productand ProductType. Producthas a link to ProductType(it is called in the database ProductTypeId), and ProductTypehas two columns ( Idand Name).
I can get a drop-down list that will be correctly populated and displayed on the forum using the following code:
Controller:
var typeList = new SelectList(_entities.ProductType.ToList(), "Id", "Name");
ViewData["Types"] = typeList;
View:
<%= Html.DropDownList("ProductType", (IEnumerable<SelectListItem>) ViewData["Types"]) %>
However, my problem is that it does not update the model in the controller. If you leave the code as it is, then ModelState is invalid due to a line ProductTypein the view. However, if I change it to something else, it looks like I can no longer reference it in the controller.
Barranger
source
share