You cannot call extension methods (.Count()
in your case) on dynamic variables. This is a limitation of .NET that has nothing to do with ASP.NET MVC.
So you will have to use the corresponding property. For example if those are arrays use .Length
and if they are collections use .Count
@for (int i = 0; i < ViewBag.Fonctions.Count; i++)
{
for (int y = 0; y < ViewBag.FonctionsContact.Count; y++)
{
if (ViewBag.Fonctions[i] == ViewBag.FonctionsContact[y])
{
<input type="checkbox" value="@ViewBag.Fonctions[i].IdFonction" checked/>
}
else
{
<input type="checkbox" value="@ViewBag.Fonctions[i].IdFonction"/>
}
}
}
Of course this is just some hacky stuff, the correct solution to this problem is obviously to get rid of ViewBag and use strongly typed view model where you wouldn't have had such problems at all.