title: ASP.NET MVC ViewData.Model requires casting
body: <p>I'm working on my first ASP.NET MVC application and have a strange issue. All the tutorials in regards to using strongly typed ViewData don't require casting/eval of ViewData / Model object but I get compilation errors if I don't cast to the ViewData object</p>
  
  <p>ViewData class:</p>
  
  <pre><code>public class CategoryEditViewData
  {
      public Category category { get; set; }
  }
  </code></pre>
  
  <p>Controller Action:</p>
  
  <pre><code>public ActionResult Edit(int id)
  {   
      Category category = Category.findOneById(id);
      CategoryEditViewData ViewData = new CategoryEditViewData();
      ViewData.category = category;
      return View("Edit", ViewData); 
  }
  </code></pre>
  
  <p>Works:</p>
  
  <pre><code>&lt;%=Html.TextBox("name", 
                 ((Project.Controllers.CategoryEditViewData)Model).category.Name)) %&gt; 
  </code></pre>
  
  <p>Doesn't Work:</p>
  
  <pre><code>&lt;%=Html.TextBox("name", Model.category.Name)) %&gt; 
  </code></pre>
  
  <p>Is there something that I am doing incorrectly - or do I have to cast to the object in the view all the time?</p>