New Posts New Posts RSS Feed: Question on Views and ViewModels
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Question on Views and ViewModels

 Post Reply Post Reply
Author
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post Topic: Question on Views and ViewModels
    Posted: 24-Sep-2010 at 1:16pm
Some people say that you should have one viewmodel per view. But I am wondering if that is always true. For example, you have a SalesInvoiceView which is divided into the upper portion of the form for the header information and the lower portion of the form for the detail lines in a grid. The SalesInoivceViewModel class holds an observablecollection of salesInvoiceLines which fill the grid. Next to the grid is Add/Edit/Delete buttons which pop up a window for the user to enter the detail lines etc in a form called SalesInvoiceLineView. I think that that this view should be passed the parents viewmodel and both views should share it.
 
Can anyone give me a good reason why I need two viewmodels in this case?
 
Bill
 
Back to Top
Peer View Drop Down
Newbie
Newbie
Avatar

Joined: 31-Aug-2010
Location: Netherlands
Posts: 15
Post Options Post Options   Quote Peer Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2010 at 12:07pm
Hi Bill,
I'm wondering about the same issue (http://www.ideablade.com/forum/forum_posts.asp?TID=2189&PID=8621#8621) and in my own words:

I think the viewmodel acts like  a businessprocess container with all the possible actions for a certain businessprocess. Additonally you add enough commands and navigation handles to let the view interact with the viewmodel.

Your Invoice screen handles the businessprocess "SalesInvoices" so in my opinion you should have ha viewmodel "SalesInvoiceViewModel" which contains all the entities , logic, validationrules ?? navigation (next,prev) and so on.

When I'm wrong, please let me know :)
Peer




Edited by Peer - 25-Sep-2010 at 12:11pm
Back to Top
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2010 at 12:23pm
I agree. The SaleInvoiceView should have a SalesInvoiceViewModel but does the SalesInvoiceLineView need a separate ViewModel or can it share the SalesInvoiceViewModel since the SalesInvoiceLineView is a child view of the SalesInvoiceView and can't exist without it.
 
Bill
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down