动态表单构建和传递查询参数
我正在开发一个根据数据库中的一些元数据表动态生成的表单。我创建名称为setting_1、setting_53、setting_22 的输入标签,其中数字是元数据的主键。由于内容是动态的,我使用 FormCollection 作为 POST 请求的唯一参数。
问题 1:是否有类似 FormCollection 的类用于 GET 请求?我想直接访问查询参数。
问题 2:如果我需要传递这些查询参数,是否有一种简单/安全的方法来构建我的 URL?
我最关心的问题之一是某些设置是通过 OAuth 填充的,因此用户将被重定向到外部页面。我必须将查询字符串作为“状态”传递,一旦用户返回,我将需要恢复该状态。我需要使用此状态来继续用户在表单输入过程中停止的位置。更重要的是,我需要一个非常简单的机制来传递查询参数。
有人处理过这样的动态页面吗?是否有传递这些页面的良好模式和实践?
I am working on a form that is generated dynamically based on some meta-data tables in my database. I create input tags with names like setting_1, setting_53, setting_22 where the number is the primary key of the meta-data. Since the content is dynamic, I am using FormCollection as the sole parameter on POST requests.
Question 1: Is there a FormCollection-like class for GET requests? I want direct access to the query parameters.
Question 2: If I need to pass these query parameters around, is there an easy/safe way to build my URLs?
One of my big concerns is that some of the settings are populated via OAuth, so the user will be redirected to an external page. I will have to pass the query string as "state" which I will need to recover once the user returns. I will need to use this state to pick up where the user left off in the form entry process. All the more reason why I need a very fool-proof mechanism for passing query parameters around.
Has anyone dealt with dynamic pages like these? Are there good patterns and practices for passing these pages around?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您当然可以查看控制器操作内部的
Request.QueryString
。但如果是我这样做,我会编写一个自定义模型绑定器。
这是一个示例模型活页夹。我没有测试过这个!
Well, you can certainly look at
Request.QueryString
inside of a controller action.But if it were me doing it, I'd write a custom model binder instead.
Here's a sample model binder. I haven't tested this!