0

Within a view model, I have the following list:

public List<Foo> ListOfFoos { get; set; }

The class Foo has the following properties:

public int id {get; set;}
public string name {get; set;}
public int number {get; set;}

I can output each Foo object in the ListOfFoos property using a foreach loop. I would like to be able to submit edited values upon submission of the form.

Is there a way to do this? Will the new values simply be stored within the ListOfFoos list?

Ryan Kohn
  • 13,079
  • 14
  • 56
  • 81
Riddick
  • 1,278
  • 4
  • 17
  • 24
  • 2
    Of course there is a way, there is always a way!:) [This blog post explains it really well](http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx) – Forty-Two Feb 01 '13 at 14:11
  • 1
    BTW, that foreach loop won't work well with mvc's model binder. You'll want to use an old school for loop so mvc can name the inputs using the indexer, and bind appropriately. – Forty-Two Feb 01 '13 at 14:20
  • I also would like to note that the MVC model binder is extremely specific and you can run into issues with case sensitivity. – da7rutrak Feb 01 '13 at 16:46
  • @EverythingGeek: I've moved your solution to the answers section. Please mark it as the answer so that others can benefit from knowing that it is the solution as well. – Ryan Kohn Dec 05 '14 at 14:53

1 Answers1

0

As mentioned by Forty-Two, Phil Haack has a popular blog post on how to bind a list to your model.

Community
  • 1
  • 1
Ryan Kohn
  • 13,079
  • 14
  • 56
  • 81