首页 > 解决方案 > Asp.net 使用 Request.Form 从 c# 中的 html 表单获取发布的值并获取数组值

问题描述

<input type=hidden name='field[size][large]' value='40' />
<input type=hidden name='field[size][medium]' value='32' />
<input type=hidden name='field[size][small]' value='12' />

<input type=hidden name='field[color][green]' value='22' />
<input type=hidden name='field[color][blue]' value='30' /> 

我有一个像这样的表格我怎么可以使用Reuest.Form.GetValues("");

但不能确定的是如何获取上面表格中的值,例如输入名称是 field[size][large]

我尝试在这里使用一些示例,但是如果我对所有表单值进行循环,则无法获取值我可以看到诸如

    foreach (string key in Request.Form)
                    { 
                        sbError.Append("<br>Key : " + key + "=" + Request.Form[key]);
                        // Do something with (name, value).
// using this will output all form values but l want specifically for field[xxx][xxx] not all
                    }

.它将输出值。我的问题是我怎样才能field[xxx][xxx] 通过它们获得 or 循环中的所有值

更新 :

我正在使用 Angular 创建 html 输入值

field['am-created-by-angular']['created-by-angular']

所以基于字段获取值并遍历它并获取值。

l 不知道用户在客户端使用 angular 创建的值,但是会有字母数字 l 只需捕获值

标签: c#htmlasp.netwebforms

解决方案


推荐阅读