开发者

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

i want to design a form in asp.n开发者_开发技巧et 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.


It is not particularly an MVC solution but I advise a client-side implementation using 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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜