I am really struggling with Html.DropdownList. Identical code worked under VS2012 but fails with the subject error under VS2013. Any help would be deeply appreciated.
Controller (selectedCredit is int):
var creditQuery = from d in db.CreditStatus
orderby d.CreditId
select new { d.CreditId, d.Reason };
ViewBag.Credit = new SelectList(creditQuery.ToList(), "CreditId", "Reason", selectedCredit);
View:
@Html.DropDownList("Credit", null, new { @class = "form-control" })
If the second parm of Html.DropdownList is not null, it will ignore selectedCredit and no item will be selected.
List list shows correctly but fails on Post with the subject error. HELP!
Once you do a POST to server the viewbag needs to be repopulated
Insert this in your post action
var creditQuery = from d in db.CreditStatus
orderby d.CreditId
select new { d.CreditId, d.Reason };
ViewBag.Credit = new SelectList(creditQuery.ToList(), "CreditId", "Reason", selectedCredit);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments