trying to set a dropdown in MVC
Posted
by RJ
on Stack Overflow
See other posts from Stack Overflow
or by RJ
Published on 2010-06-15T00:33:16Z
Indexed on
2010/06/15
0:52 UTC
Read the original article
Hit count: 179
I almost have this solved but need a little push.
Here's what I have:
In the database I have a field called active that is a bit field (True/False)
I have placed a dropdownlist on the View form like this:
<%= Html.DropDownList("lstActive", new SelectList((IEnumerable)ViewData["ActiveList"])) %>
In my controller, I simply have this code to generate the True/False in the dropdown:
List<string> activeList = new List<string>();
activeList.Add("True");
activeList.Add("False");
ViewData["ActiveList"] = new SelectList(activeList);
I want to bind to the field in the database called active and select it in the dropdown. When I view it like this I get this:
So the questions are these:
Obviously I am not pointing to the Value and Text property but what is that in this case? And how do I select the value that is in the database?
Any help would be appreciated.
© Stack Overflow or respective owner