title: ASP.NET MVC 2 DisplayFor()
body: <p>I'm looking at the new version of ASP.NET MVC (see here for more details if you haven't seen it already) and I'm having some pretty basic trouble displaying the content of an object.</p>
  
  <p>In my control I have an object of type <code>Person</code>, which I am passing to the view in <code>ViewData.Model</code>.  All is well so far and I can extract the object in the view ready for display.  What I don't get though, is how I need to call the <code>Html.DisplayFor()</code> method in order to get the data to screen.  I've tried the following...</p>
  
  <pre><code>&lt;% 
      MVC2test.Models.Person p = ViewData.Model as MVC2test.Models.Person;
  %&gt;
  // snip
  &lt;%= Html.DisplayFor(p =&gt; p) %&gt;
  </code></pre>
  
  <p>but I get the following message: </p>
  
  <blockquote>
    <p>CS0136: A local variable named 'p' cannot be declared in this scope because it would give a different meaning to 'p', which is already used in a 'parent or current' scope to denote something else</p>
  </blockquote>
  
  <p>I know this is not what I should be doing - I know that redefining a variable will produce this error, but I don't know how to access the object from the controller.  So my question is, how do I pass the object to the view in order to display its properties?</p>
  
  <p>N.B. I should add that I am reading up on this in my limited spare time, so it is entirely possible I have missed something fundamental.</p>
  
  <p>TIA</p>