如何用ASP做一个向导。Net MVC

时间:2022-10-16 04:10:08

Our site has multiple "wizards" where various data is collected over several pages, and cannot be committed to the database until the last step.

我们的站点有多个“向导”,其中在多个页面上收集各种数据,直到最后一步才能提交到数据库。

What is the best/correct way to make a wizard like this with ASP.Net MVC

用ASP创建这样的向导,最好的/正确的方法是什么?Net MVC

edit: My boss is now saying "no javascript" - any thoughts on how to get around that restriction?

编辑:我的老板现在说“不使用javascript”——关于如何绕过这个限制有什么想法吗?

8 个解决方案

#1


44  

I don't believe there is a best/correct way, but the way I'd do it is...

我不相信有最好的/正确的方法,但我的方法是……

Each wizard gets its own page. Each step gets its own div. All steps are in the same form.

每个向导都有自己的页面。每个步骤都有自己的div。所有的步骤都是相同的形式。

The previous/next buttons would essentially hide/show the div in each step of the process. The last step's submit button submits the entire form. It would be pretty trivial to implement this using jQuery, and it would be easy to maintain as all the wizard steps are in a single ViewPage.

前/下一个按钮将在流程的每个步骤中隐藏/显示div。最后一步的submit按钮提交整个表单。使用jQuery实现这一点非常简单,而且很容易维护,因为所有的向导步骤都在一个视图页面中。

On the controller side, you'd have two controller methods, the HttpVerbs.Get version that would prepare the form for viewing and the HttpVerbs.Post version that would take a FormsResult and parse it to get out the information required to submit the user's answers to storage/other processes.

在控制器端,有两个控制器方法http谓词。获取将为查看和http谓词准备表单的版本。发布版本,该版本将获取一个FormsResult并对其进行解析,以获取向存储/其他进程提交用户答案所需的信息。


Wow, your boss stinks.

哇,你的老板很臭。

This answer almost gracefully works for those ****** who have javascript disabled (yes, both of them). You can tweak it to hide the next-previous buttons via CSS and unhide them in your javascript code. This way people with javascript see the wizard and people without javascript will see the entire form (without next/prev buttons).

对于禁用了javascript的****** **(是的,两者都禁用),这个答案几乎适用。您可以调整它,通过CSS隐藏下一个之前的按钮,并在javascript代码中隐藏它们。这样,使用javascript的人可以看到向导,不使用javascript的人可以看到整个表单(没有next/prev按钮)。

The other option is to create a view for each step in the wizard. You can store the intermediate results of the form in the Session. This way would cost plenty of time and effort to implement, which means you could probably squeeze some overtime out of your boss when you demonstrate, in about twenty minutes of effort you spend during lunch, how easy the javascript route is to implement.

另一个选项是为向导中的每个步骤创建一个视图。您可以将表单的中间结果存储在会话中。这种方式将花费大量的时间和精力来实现,这意味着当您演示javascript路径实现起来有多容易时,您可能会从您的老板那里挤出一些额外的时间。

#2


20  

If you can't use JavaScript, then make each step a view, with a method in the controller, and keep your data in session until ready to submit to the database.

如果您不能使用JavaScript,那么请在控制器中使用方法使每个步骤都是一个视图,并在会话中保存您的数据,直到准备提交到数据库为止。

You can make your Next and Prev buttons using the ActionLink HtmlHelper method.

您可以使用ActionLink HtmlHelper方法创建您的Next和Prev按钮。

#3


12  

Another way is to save the incomplete object that you are building with the wizard to the database and just pass the primary key to the next step of the wizard. I know that this means you need to make some of the database fields nullable, but it does have the added advantage that you can save the primary key in a cookie and allow the user to come back to the wizard at some later time. This option doesn't require javascript or session state.

另一种方法是将使用向导构建的不完整对象保存到数据库中,并将主键传递给向导的下一步。我知道这意味着您需要使一些数据库字段成为可空的,但是它有一个额外的优势,即您可以将主键保存在cookie中,并允许用户在以后的某个时候返回向导。此选项不需要javascript或会话状态。

#4


4  

Make the different panels all be client side ... all in the same form ... and when the final submit button is pressed, you can post all of the values at the same time.

让不同的面板都是客户端……都以同样的形式……当最后提交按钮被按下时,您可以同时发布所有的值。

#5


3  

If you can't use Javascript and don't want to spend server resources with Session variables, you can also serialize and deserialize the values being entered in the different steps, and pass it back and forth using a hidden input field. A bit like ViewState in ASP.NET Webforms.

如果您不能使用Javascript,并且不希望将服务器资源用于会话变量,您还可以序列化和反序列化在不同步骤中输入的值,并使用隐藏的输入字段来回传递它们。有点像ASP中的ViewState。净Webforms。

#6


2  

I put together a login wizard and documented the ideas behind it on my blog if that helps: link text

我整合了一个登录向导,并将其背后的想法记录在我的博客上,如果有帮助的话:链接文本

#7


1  

You can use the simple component MVCWizard.Wizard available on NuGet. The WizardController allows you to create a wizard using partial view. There is also the AutoWizardController that renders the entire wizard in a single view. All these components operate with the session to store the model state.

您可以使用简单的组件MVCWizard。NuGet向导可用。向导控制器允许您使用部分视图创建向导。还有一个AutoWizardController,它在一个视图中呈现整个向导。所有这些组件都使用会话来存储模型状态。

#8


1  

There is a very simple, flexible and extensible method in this question: How to simplify my statefull interlaced modal dialogs in ASP.NET MVC

在这个问题中有一种非常简单、灵活和可扩展的方法:如何简化我在ASP中的状态满交错的模态对话框。NET MVC

#1


44  

I don't believe there is a best/correct way, but the way I'd do it is...

我不相信有最好的/正确的方法,但我的方法是……

Each wizard gets its own page. Each step gets its own div. All steps are in the same form.

每个向导都有自己的页面。每个步骤都有自己的div。所有的步骤都是相同的形式。

The previous/next buttons would essentially hide/show the div in each step of the process. The last step's submit button submits the entire form. It would be pretty trivial to implement this using jQuery, and it would be easy to maintain as all the wizard steps are in a single ViewPage.

前/下一个按钮将在流程的每个步骤中隐藏/显示div。最后一步的submit按钮提交整个表单。使用jQuery实现这一点非常简单,而且很容易维护,因为所有的向导步骤都在一个视图页面中。

On the controller side, you'd have two controller methods, the HttpVerbs.Get version that would prepare the form for viewing and the HttpVerbs.Post version that would take a FormsResult and parse it to get out the information required to submit the user's answers to storage/other processes.

在控制器端,有两个控制器方法http谓词。获取将为查看和http谓词准备表单的版本。发布版本,该版本将获取一个FormsResult并对其进行解析,以获取向存储/其他进程提交用户答案所需的信息。


Wow, your boss stinks.

哇,你的老板很臭。

This answer almost gracefully works for those ****** who have javascript disabled (yes, both of them). You can tweak it to hide the next-previous buttons via CSS and unhide them in your javascript code. This way people with javascript see the wizard and people without javascript will see the entire form (without next/prev buttons).

对于禁用了javascript的****** **(是的,两者都禁用),这个答案几乎适用。您可以调整它,通过CSS隐藏下一个之前的按钮,并在javascript代码中隐藏它们。这样,使用javascript的人可以看到向导,不使用javascript的人可以看到整个表单(没有next/prev按钮)。

The other option is to create a view for each step in the wizard. You can store the intermediate results of the form in the Session. This way would cost plenty of time and effort to implement, which means you could probably squeeze some overtime out of your boss when you demonstrate, in about twenty minutes of effort you spend during lunch, how easy the javascript route is to implement.

另一个选项是为向导中的每个步骤创建一个视图。您可以将表单的中间结果存储在会话中。这种方式将花费大量的时间和精力来实现,这意味着当您演示javascript路径实现起来有多容易时,您可能会从您的老板那里挤出一些额外的时间。

#2


20  

If you can't use JavaScript, then make each step a view, with a method in the controller, and keep your data in session until ready to submit to the database.

如果您不能使用JavaScript,那么请在控制器中使用方法使每个步骤都是一个视图,并在会话中保存您的数据,直到准备提交到数据库为止。

You can make your Next and Prev buttons using the ActionLink HtmlHelper method.

您可以使用ActionLink HtmlHelper方法创建您的Next和Prev按钮。

#3


12  

Another way is to save the incomplete object that you are building with the wizard to the database and just pass the primary key to the next step of the wizard. I know that this means you need to make some of the database fields nullable, but it does have the added advantage that you can save the primary key in a cookie and allow the user to come back to the wizard at some later time. This option doesn't require javascript or session state.

另一种方法是将使用向导构建的不完整对象保存到数据库中,并将主键传递给向导的下一步。我知道这意味着您需要使一些数据库字段成为可空的,但是它有一个额外的优势,即您可以将主键保存在cookie中,并允许用户在以后的某个时候返回向导。此选项不需要javascript或会话状态。

#4


4  

Make the different panels all be client side ... all in the same form ... and when the final submit button is pressed, you can post all of the values at the same time.

让不同的面板都是客户端……都以同样的形式……当最后提交按钮被按下时,您可以同时发布所有的值。

#5


3  

If you can't use Javascript and don't want to spend server resources with Session variables, you can also serialize and deserialize the values being entered in the different steps, and pass it back and forth using a hidden input field. A bit like ViewState in ASP.NET Webforms.

如果您不能使用Javascript,并且不希望将服务器资源用于会话变量,您还可以序列化和反序列化在不同步骤中输入的值,并使用隐藏的输入字段来回传递它们。有点像ASP中的ViewState。净Webforms。

#6


2  

I put together a login wizard and documented the ideas behind it on my blog if that helps: link text

我整合了一个登录向导,并将其背后的想法记录在我的博客上,如果有帮助的话:链接文本

#7


1  

You can use the simple component MVCWizard.Wizard available on NuGet. The WizardController allows you to create a wizard using partial view. There is also the AutoWizardController that renders the entire wizard in a single view. All these components operate with the session to store the model state.

您可以使用简单的组件MVCWizard。NuGet向导可用。向导控制器允许您使用部分视图创建向导。还有一个AutoWizardController,它在一个视图中呈现整个向导。所有这些组件都使用会话来存储模型状态。

#8


1  

There is a very simple, flexible and extensible method in this question: How to simplify my statefull interlaced modal dialogs in ASP.NET MVC

在这个问题中有一种非常简单、灵活和可扩展的方法:如何简化我在ASP中的状态满交错的模态对话框。NET MVC