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

没有正确的解决方案

其他提示

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!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top