如何创建与Webforms Wizards功能相似的MVC“向导”?

时间:2023-01-20 17:08:11

I'd like to create a wizard in ASP.NET MVC similar to the wizard control functionality found in ASP.NET webforms.

我想在ASP.NET MVC中创建一个向导,类似于ASP.NET webforms中的向导控制功能。

What is the best way to do this?

做这个的最好方式是什么?

5 个解决方案

#1


With ASP.NET MVC I would suggest using javascript/jquery to create a wizard in a web page; something like

使用ASP.NET MVC,我建议使用javascript / jquery在网页中创建向导;就像是

<script type="text/javascript">
    $().ready(InitializeWizard);
    function InitializeWizard() {
        $(".step").hide();
        $("#step1").show();
    }
    function Step1OK() {
        $("#step1").hide();
        $("#step2").show();
    }
    function Step2OK() {
        $("#step2").hide();
        $("#stepComplete").show();
    }
</script>

<div id="step1" class="step">
    Step 1
    <input type="button" onclick="Step1OK();" value="OK" />
</div>
<div id="step2" class="step">
    Step 2
    <input type="button" onclick="Step2OK();" value="OK" />
</div>
<div id="stepComplete" class="step">
    Complete
</div>

NB! Remember, in the top of the document, to load jquery, e.g. by referencing the google link:

NB!请记住,在文档的顶部,要加载jquery,例如通过引用谷歌链接:

<script src="http://www.google.com/jsapi"></script>
<script>
    google.load("jquery", "1.3.2");
</script>

#2


There is no simple way to use a wizard control in ASP.NET MVC. Because ASP.NET MVC is not Web forms, so you should stop thinking webformy and start thinking the MVC way. A better thing to do would be to leverage jQuery and partials (Partial Views) to come up with a nice user experience which walks the user through some predefined steps.

在ASP.NET MVC中使用向导控件没有简单的方法。因为ASP.NET MVC不是Web表单,所以你应该停止思考webformy并开始思考MVC的方式。更好的办法是利用jQuery和partials(部分视图)来提供良好的用户体验,引导用户完成一些预定义的步骤。

#3


ASP.NET MVC itself is a stateless design pattern meaning between requests there is no form of state. If you would like to hold some sort of state you would have to use some sort of persistant mechanism like a cookie, querystring (blah?page=2), session or maybe even in the database.

ASP.NET MVC本身是一种无状态设计模式,意味着请求之间没有任何形式的状态。如果你想保持某种状态,你将不得不使用某种持久性机制,如cookie,查询字符串(blah?page = 2),session或者甚至可能在数据库中。

#4


Try this one.

试试这个。

It uses jQuery and contains a sample project.

它使用jQuery并包含一个示例项目。

#5


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.

您可以使用NuGet上提供的简单组件MVCWizard.Wizard。 WizardController允许您使用局部视图创建向导。还有AutoWizardController,它在单个视图中呈现整个向导。所有这些组件都与会话一起运行以存储模型状态。

#1


With ASP.NET MVC I would suggest using javascript/jquery to create a wizard in a web page; something like

使用ASP.NET MVC,我建议使用javascript / jquery在网页中创建向导;就像是

<script type="text/javascript">
    $().ready(InitializeWizard);
    function InitializeWizard() {
        $(".step").hide();
        $("#step1").show();
    }
    function Step1OK() {
        $("#step1").hide();
        $("#step2").show();
    }
    function Step2OK() {
        $("#step2").hide();
        $("#stepComplete").show();
    }
</script>

<div id="step1" class="step">
    Step 1
    <input type="button" onclick="Step1OK();" value="OK" />
</div>
<div id="step2" class="step">
    Step 2
    <input type="button" onclick="Step2OK();" value="OK" />
</div>
<div id="stepComplete" class="step">
    Complete
</div>

NB! Remember, in the top of the document, to load jquery, e.g. by referencing the google link:

NB!请记住,在文档的顶部,要加载jquery,例如通过引用谷歌链接:

<script src="http://www.google.com/jsapi"></script>
<script>
    google.load("jquery", "1.3.2");
</script>

#2


There is no simple way to use a wizard control in ASP.NET MVC. Because ASP.NET MVC is not Web forms, so you should stop thinking webformy and start thinking the MVC way. A better thing to do would be to leverage jQuery and partials (Partial Views) to come up with a nice user experience which walks the user through some predefined steps.

在ASP.NET MVC中使用向导控件没有简单的方法。因为ASP.NET MVC不是Web表单,所以你应该停止思考webformy并开始思考MVC的方式。更好的办法是利用jQuery和partials(部分视图)来提供良好的用户体验,引导用户完成一些预定义的步骤。

#3


ASP.NET MVC itself is a stateless design pattern meaning between requests there is no form of state. If you would like to hold some sort of state you would have to use some sort of persistant mechanism like a cookie, querystring (blah?page=2), session or maybe even in the database.

ASP.NET MVC本身是一种无状态设计模式,意味着请求之间没有任何形式的状态。如果你想保持某种状态,你将不得不使用某种持久性机制,如cookie,查询字符串(blah?page = 2),session或者甚至可能在数据库中。

#4


Try this one.

试试这个。

It uses jQuery and contains a sample project.

它使用jQuery并包含一个示例项目。

#5


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.

您可以使用NuGet上提供的简单组件MVCWizard.Wizard。 WizardController允许您使用局部视图创建向导。还有AutoWizardController,它在单个视图中呈现整个向导。所有这些组件都与会话一起运行以存储模型状态。