So I have the following (pseudo code):
string selectedvalud = \"C\";
List list= new List();
foreach(var item in mymod
Try like this:
ViewBag.ListOfCodes = new SelectList(mymodelinstance.Codes, "Id", "Name");
ViewBag.Codes = "C";
and in your view:
<%= Html.DropDownList(
"Codes",
(IEnumerable)ViewBag.ListOfCodes,
new { style = "max-width: 600px;" }
) %>
For this to work you obviously must have an item with Id = "C" inside your collection, like this:
ViewBag.ListOfCodes = new SelectList(new[]
{
new { Id = "A", Name = "Code A" },
new { Id = "B", Name = "Code B" },
new { Id = "C", Name = "Code C" },
}, "Id", "Name");