tags:

views:

109

answers:

2

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.

A: 

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")) %>
NickLarsen
+1  A: 

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

Brad Wilson