I have below variables
public IEnumerable<SelectListItem> SelectedGroups { get; set; }
Dictionary<string,string> grpsList;
Below is my iteration
if(condition)
viemodel.SelectedGroups = selectlist1;
else
viemodel.SelectedGroups = selectlist2;
foreach (var item in viemodel.SelectedGroups) <<--Error message
grpsList.Remove(item.Value);
I am not modifying selectedgroups but using it as a reference to remove from grpsList but its failing in foreach declaration.
Added code, selectlist1 contains reference to grpsList, something like this (removed additional joins and all other code)
from g in grpsList
select g).ToSelectList(g => g.Value, g => g.Key);
selectlist2 is different list.