Form.Post中的NameValueCollection显示FIELDS和VALUES

Rav*_*Ram -1 c# asp.net collections

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

我有以下只返回FIELD但没有值.

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

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

Response.Write(frm);
Run Code Online (Sandbox Code Playgroud)

我可以添加这个frm字符串来显示VALUES吗?

更新:

我用的是初始代码

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

这很棒.我将尝试下面的新变体.

Dar*_*rov 6

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());
Run Code Online (Sandbox Code Playgroud)