Is there a better way to do things like this, instead of just passing the Model (contains lots of extra stuff) straight to the view? I'm getting tired of all the convestions!!
Model -> ViewM -> view -> ViewM ->Convert to Model -> Save
sure, thats what custom binders are for. you can also supply your own html helper to bind to the model. also there is no reason the model passed to the view, has to match the post model bound to on the controller. rememeber the postback data is just a form
post of name/value pairs.
You could create a set of entities that just contan the data you want. You have to take more control over crud operations - ie you can just let your orm completely control it. For example you could have a product entity as normal but then have a product that
only contains what you want. In your repository have a method that only gets the data you want into the mini object.
GorillaMann
Member
117 Points
332 Posts
Is there a better way to pass around view models?
Jan 25, 2013 06:38 PM|LINK
Is there a better way to do things like this, instead of just passing the Model (contains lots of extra stuff) straight to the view? I'm getting tired of all the convestions!!
Model -> ViewM -> view -> ViewM ->Convert to Model -> Save
bruce (sqlwo...
All-Star
36850 Points
5445 Posts
Re: Is there a better way to pass around view models?
Jan 25, 2013 07:46 PM|LINK
sure, thats what custom binders are for. you can also supply your own html helper to bind to the model. also there is no reason the model passed to the view, has to match the post model bound to on the controller. rememeber the postback data is just a form post of name/value pairs.
ignatandrei
All-Star
134973 Points
21638 Posts
Moderator
MVP
Re: Is there a better way to pass around view models?
Jan 26, 2013 07:48 AM|LINK
It is just ViewModel to View, via the controller.
The others are your choice.
Please see http://msprogrammer.serviciipeweb.ro/2010/03/29/asp-net-mvc-orm-and-viewmodels/
bretthargrea...
Member
10 Points
8 Posts
Re: Is there a better way to pass around view models?
Jan 26, 2013 01:59 PM|LINK