检索ASP.NET中的所有已发布值

时间:2021-11-12 01:38:41

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.

我正在创建一个ASP.NET应用程序,允许用户将表单元素添加到表单中的页面。当页面发布(通过提交按钮)时,我需要遍历表单中的所有已发布值并获取值。

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.

p.s我正在查看Request.Form,但看不到任何明显可用的内容。

Thanks.

谢谢。

2 个解决方案

#1


13  

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

Request.Form属性返回一个可以迭代的NameValueCollection:

foreach (string name in Request.Form.AllKeys) {
    string value = Request.Form[name];
    // Do something with (name, value).
}

#2


2  

    foreach (string key in Request.Form)
    {
        var value = Request.Form[key];
    }

#1


13  

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

Request.Form属性返回一个可以迭代的NameValueCollection:

foreach (string name in Request.Form.AllKeys) {
    string value = Request.Form[name];
    // Do something with (name, value).
}

#2


2  

    foreach (string key in Request.Form)
    {
        var value = Request.Form[key];
    }