6

我想吐出 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”,而且我知道表格上还有很多东西……

4

4 回答 4

14
StringBuilder s = new StringBuilder();
foreach (string key in Request.Form.Keys)
{
    s.AppendLine(key + ": " + Request.Form[key]);
}
string formData = s.ToString();
于 2009-09-29T15:13:44.560 回答
10
foreach(string key in Request.Form.Keys)
{
  posted += Request.Form[key].ToString();
}
于 2009-09-29T15:12:38.260 回答
3

OHHH 我发现了我的问题,在我的表单中,我不断返回的一个值来自唯一具有 NAME 的输入控件。现在我给他们起了名字,它正在工作。

于 2009-09-29T15:17:23.993 回答
0
foreach(KeyValuePair<string, string> kvp in Request.Form){
   posted += kvp.Key + ":" + kvp.Value + "\n";
}

编辑:哦。显然你必须破解 NameValueCollection才能让它做到这一点。所以这是迭代集合的不好方法。

于 2009-09-29T15:16:55.367 回答