2

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Perfect! I was wondering why I can't find the Html.BeginCollectionItem which I found in many tutorials. Now I know all the truth :D
Glad I could help. Do you have some other questions about this topic?
Not yet. I will try the solution and I suppose that everything will work finde :)
Thank you again. The class worked perfect. I only could not use Html.BeginCollectionItem ... I had to use MyNamespace.HtmlPrefixScopeExtensions.BeginCollectionItem(Html, "Registrations") instead, but that is absolutely ok.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.