POST question

Last post 06-16-2008 1:45 AM by Zhao Ji Ma - MSFT. 3 replies.

Sort Posts:

  • POST question

    06-09-2008, 12:27 PM
    • Loading...
    • scareya
    • Joined on 06-03-2008, 7:31 PM
    • Baltimore
    • Posts 41

     What's the C# equivalent of the following PHP code:

     

    foreach($_POST as $value)

    {

     echo $value;

     

    I can only seem to access it through Request["name_of_input"], but I can't seem to loop through the array without getting an error.

     

    Thanks. 

    JHU
  • Re: POST question

    06-09-2008, 12:32 PM
    Answer
    • Loading...
    • docluv
    • Joined on 06-29-2002, 11:16 PM
    • Willow Spring NC
    • Posts 1,526
    • ASPInsiders
      TrustedFriends-MVPs

    Request.Form[varName] should be what you are looking for. You can access both the POST and QueryString parameters with Request[varName]. You can also check the Request object in the Watch while you are debugging to see all the variables and any nest children.

  • Re: POST question

    06-09-2008, 12:41 PM
    • Loading...
    • scareya
    • Joined on 06-03-2008, 7:31 PM
    • Baltimore
    • Posts 41

    That only gives me the value of my Submit button (and the name).  I'm looking to get an array of all the POST variables values. 

    JHU
  • Re: POST question

    06-16-2008, 1:45 AM
    Answer

    Hi,

    Here is an example reads the values in the form collection.

    1    int loop1;
    2    NameValueCollection coll;
    3    
    4    //Load Form variables into NameValueCollection variable.
    5    coll=Request.Form;
    6    // Get names of all forms into a string array.
    7    String[] arr1 = coll.AllKeys;
    8    for (loop1 = 0; loop1 < arr1.Length; loop1++) 
    9    {
    10      Response.Write("Form: " + arr1[loop1] + "&lt;br>");
    11   }
    

    Zhao Ji Ma
    Sincerely,
    Microsoft Online Community Support

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter