c# - 如何在不知道任何细节的情况下遍历Request.Form?

标签 c# asp.net request.form

我想吐出 Request.Form 中的所有内容,这样我就可以将它作为字符串返回,看看我在处理什么。我尝试设置一个 for 循环...

// Order/Process
// this action is the submit POST from the pricing options selection page
// it consumes the pricing options, creates a new order in the database,
// and passes the user off to the Edit view for payment information collection

[AcceptVerbs(HttpVerbs.Post)]
public string Process()
{
    string posted = "";
    for(int n = 0;n < Request.Form.Count;n++)
        posted += Request.Form[n].ToString();
    return posted;
}

但我得到的只是“12”,我知道表格上还有很多东西......

最佳答案

StringBuilder s = new StringBuilder();
foreach (string key in Request.Form.Keys)
{
    s.AppendLine(key + ": " + Request.Form[key]);
}
string formData = s.ToString();

关于c# - 如何在不知道任何细节的情况下遍历Request.Form?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1493189/

相关文章:

c# - 具有通用类型的 MS CRM 自定义工作流事件输出

c# - 一个上下文引用 LINQ 查询抛出多个引用异常 - BUG?

c# - 无法将类型 X 转换为类型 Y。LINQ to Entities 仅支持转换 EDM 基本类型或枚举类型

asp.net - Devexpress 网格延迟加载

asp.net - 从客户端检测到潜在危险的 Request.Form 值

javascript - 向 Flask 提交多个表单(400 BAD REQUEST)

c# - Windows Mobile 按钮文本换行

asp.net - 如何赋予 Owin 用户身份?

jquery - ASP.NET MVC + 使用 jquery ajax 发送编码字符串