如何在不知道任何细节的情况下遍历Request.Form?
我想吐出 Request.Form 中的所有内容,这样我就可以将其作为字符串返回并查看我正在处理的内容。我尝试设置一个 for 循环...
// Order/Process
// this action is the submit POST from the pricing options selection page
// it consumes the pricing options, creates a new order in the database,
// and passes the user off to the Edit view for payment information collection
[AcceptVerbs(HttpVerbs.Post)]
public string Process()
{
string posted = "";
for(int n = 0;n < Request.Form.Count;n++)
posted += Request.Form[n].ToString();
return posted;
}
但我得到的只是“12”,而且我知道表单上还有很多东西...
I want to spit out everything in Request.Form so I can just return it as a string and see what I am dealing with. I tried setting up a for loop...
// Order/Process
// this action is the submit POST from the pricing options selection page
// it consumes the pricing options, creates a new order in the database,
// and passes the user off to the Edit view for payment information collection
[AcceptVerbs(HttpVerbs.Post)]
public string Process()
{
string posted = "";
for(int n = 0;n < Request.Form.Count;n++)
posted += Request.Form[n].ToString();
return posted;
}
But all I ever get back is '12' and I know there are a lot more things on the form than that...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
编辑:哦。显然,您必须 破解 NameValueCollection 才能做到这一点。所以这是迭代集合的糟糕方法。
Edit: Oh. Apparently you have to hack the NameValueCollection to get it to do this. So this is a bad way to iterate over the collection.
OHHH 我发现了我的问题,在我的表单中,我不断返回的一个值来自唯一具有 NAME 的输入控件。现在我给它们起了名字,它就起作用了。
OHHH I figured out my problem, in my form the one value that I keep getting back is from the only input control that has a NAME. Now that I give them names, it is working.