Retrieve all posted values in ASP.NET

2020-03-01 18:38发布

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.

2条回答
你好瞎i
2楼-- · 2020-03-01 19:06

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).
}
查看更多
够拽才男人
3楼-- · 2020-03-01 19:06
    foreach (string key in Request.Form)
    {
        var value = Request.Form[key];
    }
查看更多
登录 后发表回答