简体   繁体   中英

what is the best way to design a wizard form in ASP.NET MVC

i want to design a form in asp.net in Wizard style. do something in click next.

the form have 3 step

  1. fill your information

  2. add element [here if you type something wrong then you can edit or delete them before going to next step]

  3. finish

what is the best practise to design this in ASP.NET MVC with a power of ajax.

are anyone show me the best way i can use to do this in MVC

Here's how you could proceed: the elements of each step of the wizard could go into a separate div. The Next and Previous buttons will show/hide the corresponding div. On the last step there will be a submit button which would send the entire form to the server.

You might also take a look at the jquery form wizard plugin .

One of the ways that I have implemented a wizard is to have a separate database table that contains all of the information you are required to store and to save/retrieve data to that table in each step of your wizard - obviously depending on the size and purpose of the wizard this may not be sensible with the number of database calls but I was implementing only a 5 page wizard with maximum 5-10 fields on each page. So when you land on a page you query the database and retrieve the information from the database or if it doesn't exist load a blank page where the user can then enter the information and it is saved when they click either Next or Previous.

For navigating between pages I simply built a helper class that accepted the page name and button type (Next/Previous) and had a simple switch statement which would return the page to navigate to and then used that in a RedirectToAction statement. Again this may not suit a larger application but you could also look at using Windows Workflow (touched on in this article http://www.devx.com/dotnet/Article/29992 ) as I know that it can be used to create wizard style applications.

它不是特别的MVC解决方案,但我建议使用JQuery LightBox进行客户端实现。

You don't need any client side stuff to achieve this, it's also bad practise to use javascript for anything other than user convenience.

You have 2 problems with a wisard:

1: maintaining state. ie saving data between requests.

2: figuring out which action (usually next or previous) to take.

Maintaining state.

You can use the session object but ideally (and so you can unit test them) all actions should be pure functions. I use hidden inputs to save data between requests.

User actions.

For a next / previous view. Add 2 submit buttons to your form and give them names. When you POST the form, the button with the none null value was the button pressed. Then redirect to the appropriate action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM