title: I am getting an System.NullReferenceException error I cannot understand
body: <p>I am getting this error:</p>
  
  <blockquote>
    <p>"An exception of type 'System.NullReferenceException' occurred in
    App_Web_lmzivtl2.dll but was not handled in user code. Additional
    information: Object reference not set to an instance of an object."</p>
  </blockquote>
  
  <p>And here is the code I was using: </p>
  
  <pre><code>    @model IEnumerable&lt;PtExamen.Models.Teste&gt;
  
     @{
         ViewBag.Title = "Teste";
         Layout = "~/Views/Shared/_Layout.cshtml";
     }
  
     &lt;h2&gt;Teste&lt;/h2&gt;
      @{foreach (var item in Model )
      {
         &lt;p&gt;
            &amp;nbsp     @Html.Raw(ViewBag.Descriere)  &lt;br&gt; &lt;br&gt;
            &amp;nbsp &amp;nbsp  &lt;a href="@ViewBag.NumeFisier" target="_blank"&gt;@ViewBag.test&lt;/a&gt;)                                
         &lt;/p&gt;
     }
     }
  </code></pre>
  
  <p>I do not understand why this error came to be since i have used similar examples of this so far and I did not get this problem. Any help, explanation would be great. Thanks in advance!</p>
  
  <p>I used something similar elsewhere and this error did not take place and I cant really find what made this part of the code not cause any problems and the other did. Here is another place I used something similar but I did not have any problems:</p>
  
  <pre><code>@model IEnumerable&lt;PtExamen.Models.Capitole&gt;
  @{
      ViewBag.Title = "Index";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  
  
  
  &lt;div&gt;
      &lt;div id="div-1"&gt;
       &lt;p&gt;&lt;h2&gt; @ViewBag.MateriaSelectata.ToUpper()&lt;/h2&gt;&lt;/p&gt;
      &lt;/div&gt;
  
      &lt;div id="div-1a"&gt;
  
              @foreach (var item in Model)
              {
                  string materiasel = ViewBag.MateriaSelectata;
                  int cidSelectat = Convert.ToInt32(ViewBag.cidSelectat);
                 &lt;p&gt;@Html.ActionLink(item.den_capitol, "Index", new { materia = item.disciplina , cid = item.id }) &lt;br&gt;&lt;/p&gt;
  </code></pre>