Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 Razor - Drop down list within Html list

I've got a list of objects that have a Name and a list of values and another property representing the SelectedValue.

I wanted to display the Name and then have a drop down - but not sure how to do it!

Can anyone assist please?

With the following example p.Name works, its the p.Values and p.SelectedValues bits that don't!

<div id="gridProps">
    <ul id="props">
    @foreach (var p in Model.AvailableProperties)
    {
        <li>@p.Name : @Html.DropDownListFor(p.SelectedValue, p.Values)</li>
    }
    </ul>
</div>
like image 370
Andy Clarke Avatar asked Dec 21 '25 07:12

Andy Clarke


1 Answers

I think what you are looking for is @Html.DropDownList instead of @Html.DropDownListFor

@Html.DropDownList actually has the overload that you're looking for:

@Html.DropDownList(string name, IEnumerable<SelectListItem> selectList)


All of the @Html.DropDownListFor overloads take an Expression<Func<...>> as the first parameter, and it doesn't look like that's what you're passing in your call.

like image 134
Sergi Papaseit Avatar answered Dec 23 '25 23:12

Sergi Papaseit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!