开发者

ASP.NET MVC save data between controllers

开发者 https://www.devze.com 2023-01-20 03:52 出处:网络
Assume the following scenario. You have three controllers: getFirstData getSecondData useFirstData The workflow of your site requires that the user first uses the getFirstDat开发者_JAVA百科a cont

Assume the following scenario. You have three controllers:

  1. getFirstData
  2. getSecondData
  3. useFirstData

The workflow of your site requires that the user first uses the getFirstDat开发者_JAVA百科a controller, and inputs some data (let's say an int) in the view. I then need to use the second controller (getSecondData) for something else. Only then does he use the third controller (useFirstData), and needs the original data he inputted in the first controller.

What is the most appropriate way to hang on to that data?

I can pass it along in the model I created through the controllers, but that requires me to "update" the value I pass inside the views, which seems "hackish".

A global variable seems "wrong".

What is the standard way?


Use dictionary TempData


It sounds like you're trying to create a wizard type workflow. Here are some other questions which might help.

How do I make a wizard with asp.net mvc
How do I handle page flow in MVC, particularly asp.net


Just save to the database between each step.

If you don't want to do a round-trip, try a JQuery Wizard plugin, like this one.


If you need a Wizard and you're using jQuery give a look to jWizard. It rocks!

0

精彩评论

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