Set a dropdown option to selected based on get variable in url in Razor MVC
Posted
by
Mason240
on Stack Overflow
See other posts from Stack Overflow
or by Mason240
Published on 2012-12-17T03:54:27Z
Indexed on
2012/12/17
11:03 UTC
Read the original article
Hit count: 297
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.
© Stack Overflow or respective owner