tags:

views:

146

answers:

2

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.

A: 

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) %>
David Liddle
I'm not using ViewData...I'm passing in an object from RenderPartial helper. Since I strongly typed my Partial View, I should be able to just use Model. I just don't know how to create the SelectList.
CoffeeAddict
sorry I should have put model.Options, i've edited it now
David Liddle
A: 

You can try this:

<% 
    Html.DropDownList(Model.Name, new SelectList(Model.Options));
%>
murki
thanks, I ended up trying just that. I think it may work but I'm not getting anything rendered yet due to other logic that I have that's causing issues. Let me try to resolve and see if this will actually work.
CoffeeAddict