views:

310

answers:

2

I am writing a survey application, and I have a form that can have potentially hundreds of input fields. How would I write the controller to process this form? I can't specify each input as a parameter for the controller, that would be unrealistic.

I found out about the MVCToolkit, and the UpdateFrom() method, but is this the right way to go? If so, how would I install the MVCToolkit in my app?

+2  A: 

It is actually way simpler than that. You just need to use an object called FormCollection.

public ActionResult MyFormUpdate (int id, FormCollection form) {
    // do form updates
}
Nick Berardi
+5  A: 

You can accept collections as parameters in Action as well.

public ActionResult TheAction (string[] answers) {

}

Html :

<input type="text" name="answers[0]" value="" />
<input type="text" name="answers[1]" value="" />
<input type="text" name="answers[2]" value="" />
<!--and so on -->

The default model binder will automatically populate the answers array in your action with the values entered in the form.

çağdaş