Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

If I have a view called, for example, ViewDetails that displays user information in labels and has a Model called ViewDetailsModel and if I want to allow the user to click a button to edit some of these details, is it considered bad practice is I pass the entire Model in the markup to a controller method which then assigns the values for another model, using the values stored in the Model that was passed in as a parameter to that action method? If so, should there instead be a service method that gets the data required for the edit view?

For example:

In the ViewDetails view, the user clicks the edit button which calls an action method in the controller (and passes in the Model object).

The action method then uses the data in the Model object to populate another model which will be used for the EditDetails view that will be returned.

share|improve this question
    
If you use server-side cashing, than reading the model from cache could be faster than passing it around. –  superM Nov 21 '12 at 3:58
    
Is the model intended to render a partial view? If so, see this: stackoverflow.com/questions/13769707/… –  Nick Dec 10 '12 at 22:24
add comment

1 Answer

up vote 4 down vote accepted

How else would you do it? If EditDetails needs to change depending on values in ViewDetails, obviously this is the correct way to do it.

As long as you're using view-models separate from your domain models, it should be clean.

It sounds like you're just working on something complex; that's probably what is making your code a bit "ugly", not the way you've designed it.

share|improve this answer
    
Another alternative is to make the data model a singleton. I think that passing the data model instance around the view classes is a better way. –  Gilbert Le Blanc Nov 21 '12 at 14:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.