开发者

Retaining Model data when passed between views

开发者 https://www.devze.com 2023-01-23 12:15 出处:网络
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

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.


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消