views:

202

answers:

4

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...

+6  A: 
foreach(string key in Request.Form.Keys)
{
  posted += Request.Form[key].ToString();
}
AJ
+1 That's the one :)
Andrew Hare
+2  A: 
StringBuilder s = new StringBuilder();
foreach (string key in Request.Form.Keys)
{
    s.AppendLine(key + ": " + Request.Form[key]);
}
string formData = s.ToString();
RedFilter
A: 
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.

Mike Blandford
Specified cast is not valid.
shogun
+2  A: 

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.

shogun