I have the following data in the controller
private void GetCountryLists(string value)
{
List<country> countries = new List<country>();
country _country = new country() { countryname = "Select a country", value = "0" };
country _country1 = new country() { countryname = "India", value = "India" };
country _country2 = new country() { countryname = "USA", value = "USA" };
countries.Add(_country);
countries.Add(_country1);
countries.Add(_country2);
ViewData["country"] = new SelectList(countries, "value", "countryname", value);
}
The country class is as follows,
public class country
{
public string countryname { get; set; }
public string value { get; set; }
}
Now, how do i use the ViewData["country"] data from the view page using the Html.DropDownListFor<>() to display the country list. In the viewpage, i have the Model property from which i can get the user's country value. I have to display the user country in the dropdown list with the selection of the current user's country.
This code is for the edit page.
Kindly suggest me a simple approach so that i can learn and use as i am a newbie developer.