2

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.

2
  • If you use server-side cashing, than reading the model from cache could be faster than passing it around.
    – superM
    Commented Nov 21, 2012 at 3:58
  • Is the model intended to render a partial view? If so, see this: stackoverflow.com/questions/13769707/…
    – NickSuperb
    Commented Dec 10, 2012 at 22:24

1 Answer 1

4

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.

1
  • 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. Commented Nov 21, 2012 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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