title: asp.net mvc 3 view looping through model with foreach
body: <p>I am having a view with tied to a model:</p>
  
  <pre><code>@model IEnumerable&lt;AJA.Models.DB.Article&gt;
  </code></pre>
  
  <p>all I want to do is to loop through the model to do some logic:</p>
  
  <pre><code>@foreach (var item in Model)
  {
      var article = item.article1;
      if (article.Length &gt; 500)
      {
          article = article.Substring(0, 500) + "...";
      }
  </code></pre>
  
  <p>However, when I execute the View, error:</p>
  
  <pre><code>exception: System.NullReferenceException: The reference of the object is not defined 
  to an instance of the object.
  </code></pre>
  
  <p>If I do <code>@Html.DisplayFor(modelItem =&gt; item.article1)</code> alone, I get the article OK, but I want to do business logic beforehand.</p>
  
  <p>What' s wrong with it ?</p>