Change your DropDownList like below:
@Html.DropDownList("id_category", new SelectList(list_cat, "Id_category", "CName", Model.Id_category))
문제
I have used this snippet in my view
<SELECT name="id_category">
@for (int item = 0; item < list_cat.Count; item++){
if (@list_cat[item].Id_category == @Model.Id_category) {
<OPTION VALUE="@list_cat[item].Id_category" selected >@list_cat[item].CName</OPTION>}
else{
<OPTION VALUE="@list_cat[item].Id_category" >@list_cat[item].CName</OPTION>
}
}
</SELECT>
then, i replaced it by
@Html.DropDownList("id_category", new SelectList(list_cat,"Id_category","CName"))
But the condition of selection of the item is missing.
How can i replace it with Html.DropDownList
? Any suggestions?
해결책
Change your DropDownList like below:
@Html.DropDownList("id_category", new SelectList(list_cat, "Id_category", "CName", Model.Id_category))