James Stevenson
James Stevenson

Reputation:

ASP MVC won't render selected value for a Select List

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.

Upvotes: 1

Views: 232

Answers (2)

Brad Wilson
Brad Wilson

Reputation: 70586

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

Upvotes: 1

Nick Larsen
Nick Larsen

Reputation: 18877

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")) %>

Upvotes: 0

Related Questions