Question

I have a Model with an IEnumerable of Registrations. On my page you have the chance to add or remove a registration via jQuery. I tried to do the new registrations with partial views, but my form has only sent the first entry. So I've read to use the Html.EditorFor. But now I can't find how to dynamically add new entries with jQuery.

Do you have any hint for me?

Was it helpful?

Solution

I would recommend you reading the following article which illustrates a step-by-step guide on how to achieve exactly that. It uses a custom BeginCollectionItem helper which allows for generating proper names for the input fields on each row so that the values are correctly bound when the form is submitted. The standard helpers use integer indexes for the collections which is problematic when adding/removing rows on the client => you will have to resynchronize those indexes. On the other hand the approach illustrated in this article uses Guids for the keys.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top