I have error The given key was not present in the dictionary.
in Razor view
Please check below code
<select class="form-control" name="country" id="country">
<option value="">Select Country</option>
@foreach (var country in ViewBag.countryList)
{
<option @((country.CountryCode == "GB") ? "selected" : "") value="@country.CountryCode">@country.CountryName</option>
}
</select>
My Country
Model Class
public class Country
{
public long CountryId { get; set; }
public string CountryCode { get; set; }
public string CountryName { get; set; }
}
For ViewBar.countryList
i add like this
List<Country> countryList = Common.getCountry();
ViewBag.countryList = JsonConvert.SerializeObject(countryList);
Please check in below image i already got data in variable but i also get error as above.