I have a list that I created in the controller:
var PayList = new[] { new ListEntry { Id = 1, Name = "" }, new ListEntry { Id = 2, Name = "Yes" }, new ListEntry { Id = 3, Name = "No" } }; ViewBag.PayList = new SelectList(PayList, "Id", "Name");
In the view, I have the following:
@Html.DropDownList("Pay", new SelectList(ViewBag.PayList,"Id","Name"))
When I try to display it, it says the following: DataBinding: "System.Web.Mvc.SelectListItem" does not contain a property named "Id". I donβt know why this is not working.
Just like me, by default, select a value in the selection list. I like the default "Yes." I thought there was a way to do this from the controller.
source share