I am using ASP.NET MVC 2 (.NET 3.5) and I need to manually determine what the list of options should be. When I do this, I get a drop-down menu, with each of the manual entries reading "System.Web.Mvc.SelectListItem".
My view model defines a list as such:
public SelectList YesNoList
{
get
{
List<SelectListItem> tmpList = new List<SelectListItem>();
tmpList.Add(new SelectListItem {Text = "", Value = ""});
tmpList.Add(new SelectListItem {Text = "Yes", Value = "1"});
tmpList.Add(new SelectListItem {Text = "No", Value = "0"});
YesNoList = new SelectList(tmpList,"");
}
private set{}
}
In the view, I reference this with an Html.DropDownList:
Html.DropDownList("FieldName", viewmodel.YesNoList);
What I expect to get on the last web page should look like this:
<select id="FieldName" name="FieldName">
<option value=""/>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
Instead, I get:
<select id="FieldName" name="FieldName">
<option>System.Web.Mvc.SelectListItem</option>
<option>System.Web.Mvc.SelectListItem</option>
<option>System.Web.Mvc.SelectListItem</option>
</select>
, , , , - , viewmodel, . SelectList #, SelectList .
, , - .
,
J