Set a dropdown option to selected based on get variable in url in Razor MVC
- by Mason240
I have a dropdown menu in a GET form. When the user hits submit, they are directed to the same page and shown the form again. I would like to have the dropdown option the user displayed in the last page already selected. So for example:
@Html.DropDownList("Type", null, "Type", new { @class = "sbox-input" } )
website.com/Search?Type="Beef"
<select name="Type">
<option value="Fish" >Fish</option>
<option value="Chicken" >Chicken</option>
<option value="Beef" selected="selected">Beef</option>
</select>
A jQuery solution would work just as well.