ViewModel, how to set the selected value in dropdownlist mvc. This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL). ), also wat in the functionality difference between html.dropdownlist and html.dropdownlistfor. First, we will discuss creating the DropDownList using the hard-coded value then we will see how to create the DropDownList with the values coming from a database. // GET: Home. The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Now its time to create a VIEW for MemberEntry. Getting the selected dropdownlist value in server side while user submit the form. Provide an answer or move on to the next question. The HtmlHelper class in MVC provides two extension methods to generate the <select> element in a view. By adding this parameter, or using FormCollection as another answer has suggested, you're asking MVC to specifically look for a form element with that name, so it should then populate the parameter value with the posted value. its source of data. If you continue to use this site we will assume that you are happy with it. its source of data. ( @Html.ValidationMessageFor(model=>model.MemberName. When static values are declared on the dropdownlist control and then then upon change of selected index, or any other post back that does not imply declaratively the reset of the ddl selected value, the value always persists through postbacks. To get connection strings from web.config file. What's happening in your code now, is you're passing the first string argument of "ddlVendor" to Html.DropDownList, and that's telling the MVC framework to create a