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
ViewData class:
public class CategoryEditViewData
{
public Category category { get; set; }
}
Controller Action:
public ActionResult Edit(int id)
{
Category category = Category.findOneById(id);
CategoryEditViewData ViewData = new CategoryEditViewData();
ViewData.category = category;
return View("Edit", ViewData);
}
Works:
<%=Html.TextBox("name",
((Project.Controllers.CategoryEditViewData)Model).category.Name)) %>
Doesn't Work:
<%=Html.TextBox("name", Model.category.Name)) %>
Is there something that I am doing incorrectly - or do I have to cast to the object in the view all the time?