Doug Chamberlain
Doug Chamberlain

Reputation: 11351

Edit a model over several views

Is it possible to have one model that you break up into several views so that the user is not overwhelmed by the amount of data they will need to input? I'm trying to build a turbo tax like interface where a question or two are asked, then the user clicks next to answer the next set of questions and so on.

The Model doesn't seem make sense to break up into more models. Since it is a single distinct entity, like a questionnare.

Upvotes: 0

Views: 212

Answers (2)

gram
gram

Reputation: 2782

See similar question for a nice example:

multi-step registration process issues in asp.net mvc (splitted viewmodels, single model)

Upvotes: 1

Tz_
Tz_

Reputation: 2949

It is possible to use the same model for multiple views, but you should decide how you want to preserve the state as you go though this "wizard". One approach can be to cross-post between the views and keep the state in post data, but in that case you have to add a lot of hidden fields for all model properties that are otherwise not displayed in an input on the current view. Another approach can be to persist the partially filled model, with the additional benefit, that the user might be able to continue after a session timeout or another problem, but then you might need to clean up stale data and be flexible in the validation on the database level. You can also preserve the state in the session if you want. Finally, you can also keep the state in the browser independent from the post data and do only AJAX calls with the server until you reach the point when you want to save everything.

Upvotes: 0

Related Questions