title: unpacking viewdata in foreach statement
body: <p>So I packed some query results in a viewdata statement.</p>
  
  <p>I can verify the correct number of results are put into the viewdata object in the view with this directive:</p>
  
  <pre><code>@foreach (var action in (List&lt;LemonadeTrader.Models.Message&gt;)ViewData["messages"]) {
  </code></pre>
  
  <p>When I try to display the results:</p>
  
  <pre><code>@Html.DisplayFor( (LemonTrader.Models.Message)action.msg)   // action.msg should be of type string
  </code></pre>
  
  <p>It says it couldn't convert string to LemonTrader.Models.Lemon.</p>
  
  <p>When I cast it as:</p>
  
  <pre><code>@Html.DisplayFor( (string)action.acidity)
  </code></pre>
  
  <p>It says:</p>
  
  <blockquote>
    <p>The type arguments for method
    'System.Web.Mvc.Html.DisplayExtensions.DisplayFor(System.Web.Mvc.‌
    ​HtmlHelper,
    System.Linq.Expressions.Expression>)'
    cannot be inferred from the usage. Try
    specifying the type arguments
    explicitly.</p>
  </blockquote>
  
  <p>Not casting it at all doesn't work either.</p>
  
  <p>How do I cast the result?</p>