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
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
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
}
}
Even easier:
public ActionResult MyMethod(string[] fieldName)
Or use List<string> if you prefer that instead of string[].