title: The given key was not present in the dictionary. in Razorview
body: <p>I have error <code>The given key was not present in the dictionary.</code> in Razor view</p>
  
  <p>Please check below code</p>
  
  <pre><code>&lt;select class="form-control" name="country" id="country"&gt;
      &lt;option value=""&gt;Select Country&lt;/option&gt;
      @foreach (var country in ViewBag.countryList)
      {
          &lt;option @((country.CountryCode == "GB") ? "selected" : "") value="@country.CountryCode"&gt;@country.CountryName&lt;/option&gt;
      }
  &lt;/select&gt;
  </code></pre>
  
  <p>My <code>Country</code> Model Class</p>
  
  <pre><code>public class Country
  {
      public long CountryId { get; set; }
      public string CountryCode { get; set; }
      public string CountryName { get; set; }
  }
  </code></pre>
  
  <p>For <code>ViewBar.countryList</code> i add like this</p>
  
  <pre><code>List&lt;Country&gt; countryList = Common.getCountry();
  ViewBag.countryList = JsonConvert.SerializeObject(countryList);
  </code></pre>
  
  <p>Please check in below image i already got data in variable but i also get error as above.</p>
  
  <p><a href="https://i.stack.imgur.com/XuMu6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XuMu6.png" alt="enter image description here"></a></p>