Zoinky
Zoinky

Reputation: 5029

ASP.NET MVC Passing Data Between Views

I am creating an app that I need to pass a value around, this will be equivalent to a username, where the first part of the wizard will create the username and this username will be passed between views to fill out the rest of the form.

What are the best practices to pass this value around, is it pass it as part of each view form submit (make it a hidden field) of each form or what is the best way. Storing this in the session is not idea as I do not want to lose the value after session time out.

I just like to understand what the best practices are. I also would not like this value to be visible to the user (not part of querystring)

EDIT:

for clarity, i already use database to persist the state of my data, I am talking about passing ONE field around so that I can load/save rest of the data to the same ID.

Upvotes: 0

Views: 98

Answers (1)

moribvndvs
moribvndvs

Reputation: 42497

If you're dealing with a complex graph and/or you want it persistent, you would either need to use a database-backed Session or just create your own database entity and update it between stages of the wizard.

Hidden fields or even cookies are possibilities, but they'd only be reasonable to manage for small amounts of data, and you mentioned you don't want to expose the data to end users. You could just encrypt the serialized object containing your wizard state, kinda like view state does, and pass it via a hidden if you don't want to write persistence for it. But since you did say you don't want to lose state between sessions, maybe it'd be most sensible to just store it in the database as I mentioned.

No hard and fast rule, just enumerate your requirements and go for it.

Upvotes: 1

Related Questions