Your SlideShare is downloading. ×
04 view models
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

04 view models

204
views

Published on

Published in: Technology, Business

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
204
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. View models Demystified1
  • 2. 2 A model is a software representationof a real world object or API that wewant to work with›  a.k.a. – A class!
  • 3. Remember, the controller Model creates the model andpasses it to the view Controller View Surfer
  • 4. 4 Passing a model to the view looks likethis:public ActionResult ShowPerson(){ var p = new Person() { FirstName = "Amy", MiddleName = "Farrah", LastName = "Fowler", Occupation = "Neurobiologist" }; return View(p);}
  • 5. 5 Suppose wehave this page›  What would our model look like?›  Its got task-related things›  Its got task-independent things
  • 6. 6 We have several options1.  Force our task class to have non-task things2.  Force our non-task classes to also store task-related things3.  Pass two or more models to the view4.  Create a third class that has a task and other non-task related things
  • 7. 7 A class that is built to work in a view isa ViewModelpublic class UpdateTaskViewModel!{! public int TaskId { get; set; }! public int? TaskCategoryId { get; set; }! public string Notes { get; set; }! public TaskStatus? Status { get; set; }! public DateTime? StartDTime { get; set; }! public DateTime? StopDTime { get; set; }! public Boolean? Billable { get; set; }! public List<SelectListItem> Categories { get; set; }! public List<SelectListItem> Statuses { get; set; }! public int? Duration { get; set; }! public List<Material> Materials { get; set; }!}!
  • 8. Hands-on view model
  • 9. 9 Conclusion›  View models are appropriate when you have disparate data that needs to be displayed in the view›  You create a class that holds all the disparate data and use that class as the model for the strongly-typed view