2

I am working on an order form. The page loads the previously saved order items into a table. The first row of the table is the add new item row with Html.EditoFor() like this:

@Html.EditorFor(m => m.OrderItems[0].Description)

Of course the [0] represents in this case nothing, this is just to demonstrate the goal. To show the existing items, a for loop is used:

for (int i = 1; i < Model.OrderItems.Count; i++)
{ @Html.EditorFor(d => d.OrderItems[i].Description)}

The order items are stored in an IEnumerable list with four properties (Desc, Partnum, Cost, Qty).

The question is: the editor row is a form and when the user presses the Add button on the page how can that form add the new item to the existing list?

Paxsentry
  • 193
  • 2
  • 14
  • Some options [here](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308) and [here](http://stackoverflow.com/questions/29161481/post-a-form-array-without-successful/29161796#29161796) –  Aug 25 '15 at 08:41
  • You can't add items to an `IEnumerable`. Use a collection such as a `List` instead. – Complexity Aug 25 '15 at 08:43
  • Sorry my mistake, it is list. Question title corrected. @StephenMuecke, thanks, checking those. – Paxsentry Aug 25 '15 at 09:08
  • how you are loading OrderItems in your action? – Sandeep Kumar Aug 25 '15 at 09:36
  • @SandeepKumar from the controller – Paxsentry Aug 25 '15 at 09:50
  • are you loading OrderItems from database or you have a hard coded list? it would be easy to answer if you share controller code. – Sandeep Kumar Aug 25 '15 at 11:00

1 Answers1

0

you can post your 'new item' to your another action ,the param is your 'new item', you can modify your existing list now