Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, everyone. I work on a mvc vb application. In my "Edit" form I have dropdown and I want my dropdown to have preselected value. In my controller my code is:

ViewBag.studyTypes = New SelectList(service.GetStudyTypesForDropDown(), "Value", "Text", oneStudy.StudyTypeName)


In my view my code is:

@Html.DropDownList("studyTypes", Nothing, "All", New With {Key .style = "width:280px;"})


But when I load the Edit view, the dropdown value is "All", not preselected as I want it to be. Can you give an advice, how to do it?

What I have tried:

The code above is what I tried but without success
Posted
Updated 28-Jan-19 2:29am

1 solution

@Html.DropDownList.SelectedIndex = 2 

It uses the index.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900