Asp – How to Handle Variable Number of Parameters in Route Method

asp.net-mvc

I want to use the same post Action method for multiple number of input fields. How can I get hold of all the parameters passed to MVC engine (in addition to the method parameter)?

e.g. Both these list of values should be handled by the method below

  1. 1,A,A
  2. 1,B,A,A

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Create(int id)
    {
    //for each variable in POST store in DB
    }

Best Answer

You can access the Request.Form collection.

foreach (string field in Request.Form) {
    string name = field;
    string value = Request.Form[field];
    //...
}