First look at what im doing :
<select onchange="location = this.value;">
<option value="default" selected="selected">Default</option>
<option value="/product/productSort?id=@Model.CategoryID&sortBy=Name&order=Asc">Name (A - Z)</option>
<option value="/product/productSort?id=@Model.CategoryID&sortBy=Price&order=Asc">Price </option>
<option value="/product/productSort?id=@Model.CategoryID&sortBy=AddedDate&order=Asc">New Added </option>
</select>
and in productSort method i’m doing sorting operation according to parameters passed to it …
but how can i retain the selected option of dropdownlist when page is render again …
You can do it by passing a URL parameter with the same name and value as the selected option:
You need to have something at the model level to accept it.
But since you are using the selected option’s value as the URL to browse to, this would not be possible.
Alternative is to have a code in the view to set the selected based on value of
sortBy.