Another issue with DropDownList selected

I am really confused in ASP.Net MVC (2.0 RC) DropDownList. It does not seem to accept my selected item.

Here is my SelectListItem list (it is created inside a loop. Selected boolean)

savingTypesList.Add(new SelectListItem() { Selected = selected, Text = type.Name, Value = "" + type.SavingTypeId });

Creating the SelectList itself ..

return new SelectList(savingTypesList, "Value", "Text", (string)selected);

And my look ..

<p>
    <label for="SavingType">Saving type</label>
    <%= Html.DropDownList("SavingType", Model.SavingType, "-- select a parameter saving type --", "")%>
    <%= Html.ValidationMessage("SavingType", "*")%>
</p>

When I check the details of the returned SelectList, it shows me the following information

alt text http://www.tx3.fi/selected.PNG

As you can see, SelectedValue is configured correctly and matches the item in the Items array. When I check the actual generated HTML, it is not selected. What's wrong?

+3
source share
2 answers

I was able to solve this problem myself.

, DropDownList "SavingType", Model.SavingType. , . , , , (, , , label for = "SavingTypeList" )

+1

MVC 1.0 .

:, DropDownList , , .

: , , Model.SavingTypeList, , . DDL , .

0

Source: https://habr.com/ru/post/1732009/


All Articles