1

I am still quite new to MVC, I had a complex form in my project. The form is student form, with all common fields such as firstname,lastname etc. On the form, it also need to add multiple addresses & notes for this student and display them. Once everything has been provided, it persist student with other data into multiple tables (I have separate address table and notes table).

Currently when user click add address button I use jquery popup an address dialog, once user complete the form, I use ajax to save the data into session, and same applies to notes. I am a bit worried, first session might be expired. second my form is more complex than what I've described, so there will be a lot of data in the session which in webform I hardly use that.

So can someone give me a better solution?

Thanks for your help.

3 Answers 3

2

How about storing all the data locally using javascript and sending it all up after the final step? Either that, or add each piece to the data store incrementally, which it sounds like you don't want to do.

I think you are right to avoid using the session for this.

Sign up to request clarification or add additional context in comments.

3 Comments

How that works? save all the data locally, I can save the chunk of data locally by returning json, but how about when I post the whole form, how do I send all those data back to my action?
Can anyone explain a little bit more?
You can put the json into a field in the form, then deserialize the json on the server. Or you can post the result using an ajax request and just pass the json as the payload.
0

There an article here wich describes the proccess of creating a wizard in mvc. It seems to a good solution for your case since the author uses jQuery to achieve it's "wizard form".

Comments

0

"I use jquery popup an address dialog, once user complete the form, I use ajax to save the data into session, and same applies to notes. "

Why not just have the popup go to its opener, find the form, and append hidden form fields? Even better, just use jquery to add visible form fields to the form.

Model binding to a list has an example of what that could look like:

<form method="post" action="/Home/Create">

<input type="text" name="[0].Title" value="Curious George" />
<input type="text" name="[0].Author" value="H.A. Rey" />
<input type="text" name="[0].DatePublished" value="2/23/1973" />

<input type="text" name="[1].Title" value="Code Complete" />
<input type="text" name="[1].Author" value="Steve McConnell" />
<input type="text" name="[1].DatePublished" value="6/9/2004" />

<input type="text" name="[2].Title" value="The Two Towers" />
<input type="text" name="[2].Author" value="JRR Tolkien" />
<input type="text" name="[2].DatePublished" value="6/1/2005" />

<input type="submit" />

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.