I am trying to save values from dropdownlist to the database using MVC 5 + Entity Framework. The values for the dropdownlist are taken from the DB (and displayed), but when I am saving the web entry then the value of the OrderSourceList is null and the OrderSourceId = 0
Model
public class OrderFullModel
{
[Display(Name = "OrderSource")]
public IList<SelectListItem> OrderSourceList {get;set;}
public int OrderSourceId { get; set; }
}
Controller
public ActionResult Create() //this is returning the right dropdownlist
{
var orderSources = _repository.All<OrderSource>().OrderBy(m => m.NameRu).ToList();
ViewBag.MyOrderSources = new SelectList(orderSources, "Id", "NameRu", 0);
return View();
}
View
@Html.LabelFor(m => m.OrderSourceList)
@Html.DropDownListFor(m => m.OrderSourceList, (SelectList)ViewBag.MyOrderSources)