C# MVC: Multi step form implementation

怎甘沉沦 提交于 2019-12-02 10:27:08

Solution 1

The way I see this you could simply save each step in the database and avoid sending step1 and step2 in step 3.

Example:

Step1 : fill in details, save to db and return a guid. Use this guid as a reference for the entire inquery.

Step2 finished save to db with the given guid but also with an enum indicating which part of the inquery you are at(car for example).

If you step back you know what inquery you are dealiing with since you have your unique guid and you just send the enum as a second parameter and you will get back the desiered data for that step. If you don't have a login it would be a good practice to have some kind of db cleanup if the user would exit the browser and not come back before finishing, scheduled task for db cleanup. Even with a login this would be good to have but with a login the user can come back to previous state.

Solution 2

If for some reason you do not want to follow the above You can save the data in the browser, if you are using ajax request and not reloading the page you could save this in objects and check if they have data after each next/back click and present data via script. I do not recommend this approach since you might lose data if the page reloads and is also script heavy.

Solution 3

You cuuld also use the mvc tempdata, more info about that here Works for a given request and in your case you would constantly need to assign data between requests untill comming to the finalysing step.

I recommend solution 1 but if you want to experiment with others I hope I have given you some help.

It will be better to send data to the server at the final step. Before that the view just toggle on button click or on tab click.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!