CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Creating a view model from a domain model

242 Views
Copy Code Show/Hide Line Numbers
[Precompile]
   public class WorkoutController : Controller
   {
       public ActionResult Index()
       {
          
               var workouts = new WorkoutRepository().GetAll();
               ViewData["workouts"] = new WorkoutIndexViewModel().Render(workouts);
               return View();
       }
 
   }
 
   public struct WorkoutIndexViewModel
   {
       public List<Model> Render(List<Workout> workouts)
       {
           var value = new List<Model>();
           workouts.ForEach(x => value.Add(new Model() {Date = x.Date, Notes = x.Notes}));
           return value;
       }
 
       public struct Model
       {
           public DateTime Date { get; set; }
           public string Notes { get; set; }
       }
   }
by David R. Longnecker
  August 10, 2009 @ 9:09pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate