If you have a model object Person and another lets say Comment and then in the same view you would like to display a persons details and comments added to that person you may want to create an intermediate object sometimes referred to as a 'data transfer object' or 'view object'. So, i create a simple class:
public class PersonDetailDTO
{
public Person PersonDetail {get; set;}
public IList<Comment> Comments {get; set;}
}
.. now i can return the result of my action as type PersonDetailDTO instead of say Person. Then the view is strongly typed to PersonDetailDTO also, making it easy for me to access the PersonDetail data and Comments collection.
For example, i use a view object like this for one of my partial views:
public class AnnouncementsPartialViewData
{
public IList<Announcement> Announcements { get; set; }
public object MonthlyPlannerRouteVals { get; set; }
public object PreSchoolRouteVals { get; set; }
public object ElementaryRouteVals { get; set; }
}
.. and the partial view header looks like this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<KsisOnline.Web.Controllers.HomeController.IndexViewData.AnnouncementsPartialViewData>" %>
.. and so i can access the typed data from that view class in the view easily like so:
<% if (Model.Announcements.Count == 0)