• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

How to create an array of form input posts in C#?

Hi, I would like to create an array that holds all of the form field's input in C#.  In php I would do something like this:

$required_fields = array();
			foreach($_POST as $key => $value){
			$required_fields[] = $key;
		}

Open in new window


I can't figure out what to do in C# though.  Anyone know how to go about this?
0
FairyBusiness
Asked:
FairyBusiness
  • 2
  • 2
2 Solutions
 
Craig WagnerSoftware ArchitectCommented:
The simplest solution would be:
string[] values = new string[Request.Form.Count];
Request.Form.CopyTo( values, 0 );

Open in new window

0
 
FairyBusinessAuthor Commented:
if my form as an id of id="signup" how would I call the form by name in your code?
0
 
Craig WagnerSoftware ArchitectCommented:
You don't call the form by name. You can only submit one form, so the Request.Form contains the posted data for whichever form was posted. Any other form on the page would not have any data posted.
0
 
FairyBusinessAuthor Commented:
thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now