2009-09-29 13 views
5

Request.Form'daki her şeyi tükürmek istiyorum, böylece onu bir ip gibi döndürüp neyle uğraştığımı görebiliyorum. Ben bir döngü için ...Request.Form ile herhangi bir ayrıntıyı bilmeden nasıl geçilir?

// 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; 
} 

kurma çalıştı Ama hiç geri almak bütün '12' ve ben çok daha fazla şeyler daha formda olduğunu biliyoruz ...

cevap

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

+1 Bu bir :) –

0
foreach(KeyValuePair<string, string> kvp in Request.Form){ 
    posted += kvp.Key + ":" + kvp.Value + "\n"; 
} 

Edit: Oh. Görünüşe göre bunu yapmak için hack the NameValueCollection'a sahip olmalısın. Yani bu koleksiyon üzerinde yinelemek için kötü bir yoldur.

+0

Belirtilen kadro geçerli değil. – BigOmega

3

OHHH Sorunumu çözdüm, formumda geri aldığım tek değer bir NAME olan tek giriş kontrolünden geliyor. Şimdi onlara isimleri verdim, çalışıyor.

İlgili konular