Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,..

I am working on Mvc3 , razor, In my controller a list of Countries is being fetched to
List<SelectListItem> Countries = new List<SelectListItem>();

List as showed above, and one of the country in the list is being selected : [selected =" true"] and stored to a
ViewData["Countries"] = Countries;
these List of countries in Viewdata are being used in drop Down list in my View .

the dropdown code is as below

@Html.DropDownList("Country", (IEnumerable<SelectListItem>)ViewData["Countries"])


so the selected list item is to be displayed in the drop-down , till der its working fine but when ever i refreshed the page in which drop-down exists, the
ViewData["Countries"]
is losing the attribute selected = "true", so the dropdown is not selecting the coutnry i want,when i refreshed the page it by default selecting the 1st list item , [select=true] is disappearing..

please say how to make the viewdata to have the selected=true value even after refresh the page,......
Posted
Comments
GateKeeper22 1-Dec-11 13:01pm    
Can you post the code that is loading the Countries ViewData. I have a feeling that is probably where the problem is but have no way to verify it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900