Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a model as follows:
C#
public class Order
{
       public Customer Customer{get;set};  
       public List<Customer> CustomerList {get;set};
}

I have a strongly typed html row as follows:

HTML
<table>
   <tr>
        <td>@Html.TextBoxFor(model => model.Customer.CustomerName)</td>
        <td>@Html.TextBoxFor(model => model.Customer.CustomerEmail)</td>
        <td>@Html.TextBoxFor(model => model.Customer.CustomerAddress)</td>
    </tr>
</table>


A new row is dynamically added when a "Add New Row" label is clicked via jQuery.

Now when I submit the form I get only the first row in the controller object in the "Customer" property (thats apt).
How can I get all rows in the form of a "CustomerList".

referring to http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/ got me a bit closer but,doesn't serve the purpose completely.

Is there a way I can achieve that?

Thanks for any help.
Posted
Updated 13-Sep-14 4:16am
v5
Comments
Nathan Minier 15-Sep-14 8:56am    
I'm just curious as to why you would want to send all rows back to the server, which is presumably the source of said rows. Seems like a complete waste of bandwidth and processing to me.
Adil S 15-Sep-14 10:52am    
Nathan, I need the list of Customers (rows) in the Controller on form gets submitted.
As of now, i'm manually binding all the rows' information through jQuery and send a JSON object to the controller action through Ajax. Is there a way of dynamically binding the rows with a model directly or does it sound too hypothetical and I would need to bind it traditionally through jQuery only?
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900