在MVC传递参数设计建议

编程入门 行业动态 更新时间:2024-10-14 06:17:37
本文介绍了在MVC传递参数设计建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你如何通过在ASP MVC的参数在两种观点,像个精灵?

How do you pass parameters in ASP MVC over two views, like a wizard?

或什么是最好的做法?

我在一个室内的bug跟踪ASP应用程序的工作被转移到MVC,我似乎无法撼动的ASPX我的头,并在原地打算。

I am working on an inhouse bug tracking ASP application being moved to MVC, I can't seem to shake the ASPX out of my head and am going in circles.

在ASPX应用程序。

第1页 - >选择项目,在查询字符串传递专案编号第2页 - >选择问题类型,通过专案编号和问题类型的查询字符串第3页 - >创建新问题,我们可以得到专案编号和问题类型的形式查询字符串

Page1 -> Select Project, pass projectId in Querystring Page2 -> Select IssueType, pass projectId and Issuetype in Querystring Page3 -> Create New Issue, we can get the projectId and IssueType form querystring

我们如何重新创建MVC上述流程?

How do we recreate the above flow in MVC?

推荐答案

有关向导式系统的常见做法是使用一个单一的<形式> 元素,在隐藏字段从previous屏幕的相关信息。

A common practice for 'wizard' type systems is to use a single <form> element, with information from previous screens in hidden fields.

编辑:每请求,下面是一个例子(我不熟悉与ASP,所以你必须转化为code :(自己本)说你有一个汽车销售网站,在您的订购表格首先你问的模型车,并在随后的屏幕为您提供了适用于该车辆的选项。

per the request, here's an example (I'm not familiar with ASP, so you'll have to translate this into code yourself :( ). Say you have a site that sells cars, and in your ordering form first you ask about the model car, and in subsequent screens you offer options that apply to that vehicle.

<form action="order-wizard.html" method="POST"> <!-- which step of the wizard are we on? --> <input type="hidden" name="step" value="1" /> <!-- Get some info from the user for the first step of the wizard --> <select name="Model"> <option value="Sedan">Sedan</option> <option value="Coup">Coup</option> <option value="Pickup">Pickup</option> <option value="Van">Van</option> </select> <input type="submit" /> </form>

当用户选择一个模型,提交表单,控制器为订单wizard.html 可以看到,步选项是1,并且知道检查用户所选择的模式。然后,它生成甘这样的页面:(假定用户选择了皮卡)

When the user selects a model and submits the form, the controller for order-wizard.html can notice that the step option is 1, and knows to check that the user selected a model. Then it gan generate a page like this: (assuming the user selected "pickup")

<form action="order-wizard.html" method="POST"> <!-- which step of the wizard are we on? --> <input type="hidden" name="step" value="2" /> <!-- Stored results from the previous stage of the wizard --> <input type="hidden" name="Model" value="Pickup" /> <!-- Additional information for the wizard. More than one option can be requested for each stage of the wizard. --> <select name="Style"> <option value="Short Bed">Short Bed</option> <option value="Long Bed">Long Bed</option> <option value="Extended Cabin">Extended Cabin</option> <option value="Dually">Dually</option> </select> <select name="Interior"> <option value="Cloth">Cloth</option> <option value="Leather"> Leather </option> </select> <input type="submit" /> </form>

如果向导需要收集更多信息,有可能是通过这种方式隐藏的投入产生额外的页面。否则,如果这是最后一页,所有信息都云集,code该页面然后可以处理的形式为正常,好像所有的输入已经在一个页面请求给用户。

If the wizard needed to collect more information, There could be additional pages produced in this way with hidden inputs. Otherwise, If this was the last page and all information was gathered, the code for that page could then process the form as normal, as though all inputs had been given by the user on a single page request.

此技术的优点是,服务器不需要缓存任何会话信息。另一个优点是,它提供了一种RESTful接口,其中从另一工具的单个页面请求可以生成所有的为形式的输入的,跳过中间向导页面。

The advantage of this technique is that the server does not need to cache any session information. Another advantage is that it provides a sort of RESTful interface, where a single page request from another tool can generate all of the inputs for the form, skipping over the intermediate wizard pages.

一个缺点是,因为页动态生成基于用户请求,客户端都会有,如果他们碰巧导航离开该页面重新开始。书签是行不通的。它不保存你任何的验证,或者说,因为这种形式的投入很容易伪造。

A disadvantage is that since the page is generated dynamically based on user requests, the client will have to start over if they happen to navigate away from the page. Bookmarks just won't work. It doesn't save you anything in validation, either, since form inputs of this sort could be faked easily.

更多推荐

在MVC传递参数设计建议

本文发布于:2023-11-25 04:49:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   建议   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!