tags:

views:

114

answers:

2

I want to create this but with additional different values for the displayed options:

<%=Html.DropDownList("", new SelectList(new[] { "Alabama", "Alaska", "American Samoa", "Arizona", "Arkansas", "California", "Colorado", "Connecticut" }))%>

IE. Alabama would be shown but the value of this selection would be AL. And I do not want to use a ViewData.

A: 

Something like this?:

<%= Html.DropDownList("state", new[] { "Alabama,AL", "Alaska,??", "American Samoa,??", "Arizona,??", "Arkansas,??", "California,??", "Colorado,??", "Connecticut,??" }
    .Select(x => new SelectListItem {
        Text = x.Split(',')[0],
        Value = x.Split(',')[1],
        Selected = x.Split(',')[0] == "Alabama"
    })
) %>
eu-ge-ne
+4  A: 
<%=
    Html.DropDownList("state", new [] { 
        new SelectListItem() {Text = "Alabama", Value = "AL"}, 
        new SelectListItem() {Text = "Alaska", Value = "AK" } 
}) %>
Robert Wilczynski