I wanted to keep my value after a post back so I passed the value to the ViewBag in the controller. On my view i have something like
<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);" name="" id="" class="filter-select">
<option selected value="">Topic</option>
@{string selectedOption = ViewBag.previous;
foreach (var topic in ViewBag.topicList)
{
<option value="/resources/categories/@topic" selected="@(selectedOption == topic ? "selected" : "")" >@topic</option>
}
}
</select>
however the selected value always ends up being the last value no matter what. Even when the viewbag is empty. Is there any way around this?