Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve all posted values in ASP.NET

I am creating an ASP.NET application that allows the user to add form elements to a page within a form. When the page is posted (via the submit button) I need to loop through ALL the posted values in the form and get the values.

I can't check for specific values as I don't know how many there will be or what they will be called.

Could someone point me in the right direction of getting ALL posted values so I can loop through them?

p.s I was looking in Request.Form but couldn't see anything obvious to use.

Thanks.

like image 365
webnoob Avatar asked Dec 13 '10 11:12

webnoob


2 Answers

The Request.Form property returns a NameValueCollection you can iterate over:

foreach (string name in Request.Form.AllKeys) {
    string value = Request.Form[name];
    // Do something with (name, value).
}
like image 170
Frédéric Hamidi Avatar answered Oct 22 '22 21:10

Frédéric Hamidi


    foreach (string key in Request.Form)
    {
        var value = Request.Form[key];
    }
like image 34
Paul Hiles Avatar answered Oct 22 '22 23:10

Paul Hiles