This is my code
@if (ViewBag.last5Articles != null)
{
List<Article> articles = ViewBag.last5Articles;
foreach (var article in articles)
{
<div class="col-md-12">
<div class="row">
<h2>@article.Title</h2>
</div>
<div class="row">
<div class="col-md-6">
<p>@article.Body</p>
</div>
</div>
</div>
}
}
I put a breakpoint on the start of the foreach loop. I can see that article is not null and it has a title and a body. But when I reach article.Body and I press F10 (Step Over) suddenly it became Null!!
"An exception of type
'System.NullReferenceException'
occurred in App_Web_ayg111kp.dll but was not handled in user code"
.
And when I finish debugging the yellow screen welcomes me with this message "Object reference not set to an instance of an object
".
Can anybody explain this problem to me please. I'm using .NET 4.5.2 and MVC 5.2