tags:

views:

151

answers:

2

Is there are way to retrieve form fields with the same name besides using modelbinders or comma splitting.

I have a few textfields with the same name and i need to loop through them and retrieve each value.

Thank you

+4  A: 

FormCollection is a NameValueCollection. That means you can do:

public ActionResult MyAction(FormCollection form)
{
  // ModelBinder will set "form" appropriately
  foreach(var value in form.Getvalues("duplicatedFieldname"))
  {
    //do something with value
  }
}
Talljoe
That worked! Thank you so much.
+3  A: 

Even easier:
public ActionResult MyMethod(string[] fieldName)

Or use List<string> if you prefer that instead of string[].

Levi