Gautam Jain
Gautam Jain

Reputation: 6849

Retaining Model data when passed between views

I have 2 views both with forms.

I use TempData to pass between views. Which works fine. View2 receives data from View1 through common Model object. The model's data comes from both View1 & View2.

But when View2's form is submitted, the model does not retain View1's data. They are all reset to null & 0.

This is understandable looking at how HTTP works.

But what is the best way to get data from multiple views in a single Model.

Upvotes: 2

Views: 173

Answers (1)

PatrickSteele
PatrickSteele

Reputation: 14697

Two possibilities to consider:

  • Use the Session to store the values from View1 in between form POSTs.
  • Place the View1 data in hidden fields on View2. That way it will be retained when View2's form is POSTed.

Upvotes: 2

Related Questions