如何在不知道任何细节的情况下遍历Request.Form?

发布于 2024-08-05 22:42:58 字数 580 浏览 2 评论 0原文

我想吐出 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南笙 2024-08-12 22:42:59
foreach(KeyValuePair<string, string> kvp in Request.Form){
   posted += kvp.Key + ":" + kvp.Value + "\n";
}

编辑:哦。显然,您必须 破解 NameValueCollection 才能做到这一点。所以这是迭代集合的糟糕方法。

foreach(KeyValuePair<string, string> kvp in Request.Form){
   posted += kvp.Key + ":" + kvp.Value + "\n";
}

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.

江湖彼岸 2024-08-12 22:42:58
StringBuilder s = new StringBuilder();
foreach (string key in Request.Form.Keys)
{
    s.AppendLine(key + ": " + Request.Form[key]);
}
string formData = s.ToString();
StringBuilder s = new StringBuilder();
foreach (string key in Request.Form.Keys)
{
    s.AppendLine(key + ": " + Request.Form[key]);
}
string formData = s.ToString();
一刻暧昧 2024-08-12 22:42:58
foreach(string key in Request.Form.Keys)
{
  posted += Request.Form[key].ToString();
}
foreach(string key in Request.Form.Keys)
{
  posted += Request.Form[key].ToString();
}
沐歌 2024-08-12 22:42:58

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文