This particular code on an aspx page of mine is driving me nuts. I get an exception saying “The given key is not present in the Dictionary” on the 3rd line, saying that ‘semester’ is not a valid key in the dictionary ‘records’. The thing is, the key I’m using has just come directly out of the dictionary! There must be something obvious I’m overlooking. Thanks.
<% foreach (var semester in records.Keys) {%>
<h3><a href="#"><%= semester.ToString() %></a></h3>
<% foreach (var course in records[semester]) { %>
<div>
</div>
<% } %>
<% } %>
I’m not sure why that would happen.
Instead, you can loop through the key-value pairs: