.NET - 获取表单字段键/值对?
我有一个带有文本框的表单,我想在提交表单后对值运行一些服务器端验证代码。我计划获取页面上的所有文本框控件并将它们添加到列表中,然后运行一个 for every 循环,该循环表示列表中的每个控件查询数据库,其中 fieldValidation.Name = Control.Name。这将返回给我一个对象和一个关联的函数,然后我可以在其中输入 Control.Value 并实际执行验证。
我的朋友告诉我构建列表是没有必要的,因为所有语言都有一种从表单获取键/值对的方法(他不了解 .NET,所以无法帮助我)。我可能在这里搜索了错误的术语,但我一直无法找到结果,或者也许我误解了我的朋友。
是否有某种字典或键/值对在提交表单时自动生成,其中包含提交的值以及......我猜还有控件?还是我只是误会他了。如果他只是说根据表单提交填充键/值对,那么在这种情况下,这对包含控件的列表有何帮助?
谢谢=)
I've got a form with textboxes and I want to run some server side validation code on the values after the form is submitted. I was planning to grab all the textbox controls on the page and adding them to a list, then running a for each loop that says for each control in the list query the database where fieldValidation.Name = Control.Name. This would return to me an object and an associated function where i coudl then input the Control.Value and actually perform the validation.
My friend told me building the list is not necessary because all languages have a way to get key/value pairs from forms (he doesn't know .NET so coudln't help me). I may be searching the wrong term here but I have not been able to find a result, or maybe I misunderstood my friend.
Is there some kind of dictionary or key/value pair automatically generated upon form submissions that contains the value that was submitted and...I guess also the control? Or am I just misunderstanding him. If he was just saying populate a key/value pair based on the form submissions, how does that help me in this situation over a list that contains the control?
Thanks =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HttpContext.Current.Request.Form : http://msdn.microsoft.com/en-us/library/system.web.httprequest.form(v=VS.71).aspx
HttpContext.Current.Request.Form : http://msdn.microsoft.com/en-us/library/system.web.httprequest.form(v=VS.71).aspx