Search code examples
asp.net-mvcasp.net-mvc-3razorasp.net-mvc-4razor-2

update a partial view using ajax and add elements to it


I'm using ASP.Net MVC 4 (C#, Entity Framework Code First) and am in a need to have a table where the user clicks on an add button and I add a product to the list (table) for this I looked everywhere and finally found the following example here:

Simple Ajax in asp.net MVC 3, update the model and rerender part

I got it to work just fine but I can't seem to get the current list (whatever is in IList in the example above) to get sent back to the action to add new rows to it. how can I do this?

I've tried to use the convention name="TheData[1].foo" for example and accept List<TheData> as a parameter to the action and nothing seems to be working.


Solution

  • It turned out that I just needed to include @Html.HiddenFor(...s for all of the values, I don't know how I missed that but that was the problem. once added it all posted back just fine.