繁体   English   中英

Form.Post 中的 NameValueCollection 显示 FIELDS 和 VALUES

[英]NameValueCollection from Form.Post show FIELDS and VALUES

我需要从 POST 中获取所有 FIELD 和 VALUES。

我有以下内容,它只返回字段但不返回值。

NameValueCollection authForm = Request.Form;
String[] a = authForm.AllKeys;

for (i = 0; i < a.Length; i++)
{
    frm += ("Form: " + a[i] + " : " + "<br>");
}

Response.Write(frm);

我可以添加什么 frm 字符串来显示值?

更新:

我使用了初始代码

    NameValueCollection authForm = Request.Form;
    foreach (string key in authForm.AllKeys)
    {
        frm += ("Key: " + key + ", Value: " + authForm[key] + "<br/>");
    }

效果很好。 我将尝试下面的新变体。

NameValueCollection authForm = Request.Form;
StringBuilder sb = new StringBuilder();
foreach (string key in authForm.AllKeys)
{
    sb.AppendFormat(
        "Key: {0}, Value: {1}<br/>", 
        HttpUtility.HtmlEncode(key), 
        HttpUtility.HtmlEncode(authForm[key])
    );
}
Response.Write(sb.ToString());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM