Carlos Blanco
Carlos Blanco

Reputation: 8762

Pass a collection of Items from the view to the controller. MVC 3

I'm trying to edit a model that contains a collection of another model as member. I'd like to create a table simulating a grid for editing this collection of items. Then, when submitting the form I want to pass the following parameters to the controller.

public ActionResult SavePerformanceGraphItem(int itemId, ICollection<PerformanceGraphItem> items)
{

}

How should I name the inputs in the view in order to be retrieved by the controller as I'd like?

Upvotes: 1

Views: 511

Answers (1)

Milimetric
Milimetric

Reputation: 13549

the names of the input fields would be something like:

name="items[0].PropertyOne"
name="items[0].PropertyTwo"
...
name="items[1].PropertyOne"
name="items[1].PropertyTwo"
...
name="items[2].PropertyOne"
name="items[2].PropertyTwo"

etc.

Upvotes: 4

Related Questions