PositiveGuy
PositiveGuy

Reputation: 47733

Populating Html.Dropdownlist

I'm trying to pass in an array to this dropdownlist in my Partial View:

<% 
    Html.DropDownList(Model.Name, Model.Options);
%>

The options are comma separated of course. It's expecting an IEnumerable so not sure what I'm missing here. It's not accepting the array.

Upvotes: 0

Views: 943

Answers (2)

David
David

Reputation: 15350

Maybe you could show us more of your code such as the value of Model.Options but here is some code that may help.

model.Options = new SelectList(values.ToList(), "Key", "Value");

<%= Html.DropDownList(Model.Name, 
                      (IEnumerable<SelectListItem>)model.Options) %>

Upvotes: 1

murki
murki

Reputation: 879

You can try this:

<% 
    Html.DropDownList(Model.Name, new SelectList(Model.Options));
%>

Upvotes: 0

Related Questions