如何使与ASP.Net MVC向导 [英] how to make a wizard with ASP.Net MVC

查看:258
本文介绍了如何使与ASP.Net MVC向导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的网站具有其中各种数据被收集在多个网页的多个向导,并且不能提交给​​数据库,直到最后一个步骤。

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

什么是最好的/正确的方法,使这样的向导与ASP.Net MVC

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

编辑:我的老板现在说不JavaScript的 - 关于如何绕过这个限制任何想法

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

推荐答案

我不相信这是最好的/正确的方式,但我会做的事情是这样的......

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.

在previous /下一个按钮将基本上隐藏/显示在这个过程中的每一步股利。最后一步的提交按钮提交整个表单。这将是pretty的琐碎使用jQuery来实现这一点,它会很容易维护,因为所有的向导步骤是在一个单一的ViewPage。

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.

在控制器端,你有两个控制器方法,该HttpVerbs.Get将prepare的形式进行查​​看和HttpVerbs.Post版本,将采取FormsResult并解析它摆脱信息版所需用户的答案提交到存储/其他过程

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.


哇,你的老板很臭。

这个答案几乎是正常工作的那些 ** 谁已禁用JavaScript(是的,他们两个人)。你可以调整它隐藏通过CSS的下一步 - previous按钮和取消隐藏在JavaScript code。这样的人用JavaScript看到向导和人没有的JavaScript将看到整个形式(不下一首/ $ P $光伏按钮)。

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路线是贯彻落实

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.

这篇关于如何使与ASP.Net MVC向导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆