1

I can only get the selected value to be selected on an MVC view when I use the ViewData object. If I try to bind directly to a property on my model which returns an Ienumerable it won't render the Selected tag into the html.

I am at a loss on this one.

Note: I do pass a strongly typed value to the View so my orginal binding was Model.Statuses where statuses is a property on my strongly typed model.

  • 2
    Can you show some code so we can see what you are doing? :) – Amadiere Oct 02 '09 at 16:39
  • this has been asked :http://stackoverflow.com/questions/222531/ienumerablestring-to-selectlist-no-value-is-selected/566492#566492 – KP. Oct 02 '09 at 16:46

2 Answers2

1

It's a bug. It's currently assigned to me, in fact. :)

Brad Wilson
  • 67,914
  • 9
  • 74
  • 83
0

In your template you are probably doing something like this:

<%= Html.DropDownList("htmlName", Model.SomeIEnumerable) %>

And you need to make it a SelectList sort of like:

<%= Html.DropDownList("htmlName", new SelectList(Model.SomeIEnumerable, "valueProperty", "textProperty")) %>
Nick Larsen
  • 18,631
  • 6
  • 67
  • 96