asp.net mvc提交表单并在url中显示所有表单参数
我的视图上有一个表单和一个相应的提交按钮。该表单负责选择某些优惠搜索的选项。主页网址如下所示:
http://localhost/
当我单击提交按钮时,将调用适当的控制器操作。但是,我希望所有表单的参数都在网址中公开(因此可以在两个人之间共享链接,例如,他们将获得相同的结果)。 例如,我怎样才能实现(例如)类似的事情:
http://localhost/?startDate=20120215&endDate=20120230&catalog=ISA
I have a form on my view and a corresponding submit button. The form is responsible for selecting options for some offers search. The homepage url looks as follows:
http://localhost/
when I click submit button, an appropriate controller's action is called. However, I would like all form's parameters to be exposed in the url (so there will be a possibility to share the link between 2 persons for instance and they will have the same results).
So for instance, how can I achieve (for instance) something like that:
http://localhost/?startDate=20120215&endDate=20120230&catalog=ISA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用表单的方法 GET,则所有变量都将成为查询字符串的一部分。
您可以使用此重载来更改表单的请求类型:
FormExtensions.BeginForm Method (HtmlHelper, String, String, FormMethod)
或者,如果您使用 RedirectToAction,则可以将参数作为对象传递:
Controller.RedirectToAction 方法(字符串、对象)
If you make the form's method GET, all of the variables will be part of the query string.
You can use this overload to change the Form's request type:
FormExtensions.BeginForm Method (HtmlHelper, String, String, FormMethod)
Or, if you're using RedirectToAction, you can pass the parameters as an object:
Controller.RedirectToAction Method (String, Object)
您应该指定使用 GET http 请求(而不是 post)提交表单,并指定您希望重定向到的操作,以便不必使用 RedirectToAction。
例如:
控制器:
模型:
视图:
但请注意,在 GET http 请求中对系统进行任何更改并不是最佳实践。如果要进行任何更改,则应在 POST 请求中执行这些更改。
You should specify that the form submits using a GET http request (rather than post) and specify the action that you wish to redirect to so that you do not have to use RedirectToAction.
For example:
Controller:
Model:
View:
But note that it is not best practise to make any changes to your system in the GET http request. If any changes are to be made then these should be performed in the POST request.
使用
http
的GET
方法提交表单,因此表单的渲染输出将类似于submit the form using
http
'sGET
method, so your form's rendered output would be like