Domanda

My code :

 @if (Model.ClientTypes != null)
 {
  foreach (var clientType in Model.ClientTypes)
  {
     @:blabla :)
  }
 }

ClientTypes collection is a list and it´s not null, there are 5 elements in ClientTypes, razor engine enters in loop and after looping all 4 elements at the end throws null exception :(

what is wrong ?

enter image description here

Nessuna soluzione corretta

Altri suggerimenti

I ran into this same problem and discovered that the error was actually lying to me. The error wasn't on the foreach loop, it was on the line following the foreach loop. So my recommendation is to comment out anything that could be null immediately following the foreach loop and then uncomment one at a time until you find the culprit. Good luck!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top