在 ASP.NET MVC 中设计向导表单的最佳方法是什么
我想在 ASP.NET 中以向导风格设计一个表单。点击下一步做一些事情。
表单有 3 个步骤
填写您的信息
添加元素 [此处如果您输入错误,则可以在进入下一步之前编辑或删除它们]
完成
在 ASP.NET MVC 中使用 ajax 功能设计此内容的最佳实践是什么。
有人告诉我在 MVC 中可以使用的最佳方法吗
i want to design a form in asp.net in Wizard style. do something in click next.
the form have 3 step
fill your information
add element [here if you type something wrong then you can edit or delete them before going to next step]
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
继续的方法如下:向导每个步骤的元素可以放入单独的 div 中。下一个和上一个按钮将显示/隐藏相应的 div。最后一步将有一个提交按钮,它将整个表单发送到服务器。
您还可以查看 jquery 表单向导插件。
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.
我实现向导的方法之一是拥有一个单独的数据库表,其中包含您需要在向导的每个步骤中存储和保存/检索数据到该表的所有信息 - 显然取决于大小和出于向导的目的,这对于数据库调用的数量可能不合理,但我只实现了一个 5 页向导,每页最多 5-10 个字段。因此,当您登陆页面时,您会查询数据库并从数据库中检索信息,或者如果数据库不存在,则加载一个空白页面,然后用户可以在其中输入信息,并在单击“下一步”或“上一步”时保存信息。
为了在页面之间导航,我简单地构建了一个辅助类,它接受页面名称和按钮类型(下一个/上一个),并有一个简单的 switch 语句,该语句将返回要导航到的页面,然后在 RedirectToAction 语句中使用它。同样,这可能不适合更大的应用程序,但您也可以考虑使用 Windows 工作流(在本文 中提到) http://www.devx.com/dotnet/Article/29992)据我所知,它可以用于创建向导样式的应用程序。
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 进行客户端实现。
It is not particularly an MVC solution but I advise a client-side implementation using JQuery LightBox.
你不需要任何客户端的东西来实现这一点,除了用户方便之外使用 javascript 也是不好的做法。
巫师有两个问题:
1:维护状态。即在请求之间保存数据。
2:弄清楚要采取哪个行动(通常是下一个或上一个)。
维持状态。
您可以使用会话对象,但理想情况下(这样您可以对它们进行单元测试)所有操作都应该是纯函数。我使用隐藏输入来保存请求之间的数据。
用户操作。
用于下一个/上一个视图。将 2 个提交按钮添加到您的表单中并为其命名。当你
POST 表单,具有非空值的按钮是按下的按钮。然后重定向到适当的操作。
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.