I\'m using Steve Sanderson\'s BeginCollectionItem approach to add dynamic content. Everything works fine when I\'m doing it on the first level. However, when try to implemen
You can use the code from JonK answer but it will not work for dynamically added partials from ajax calls because "ViewData.TemplateInfo.HtmlFieldPrefix" comes empty.
The solution is to add a property to your model with the form prefix and fill it in on the action called by the ajax function.
To fetch the form prefix using jQuery you can simply do:
// "this" a button that will trigger the ajax call and is within the div with the class "partial-enclosing-class"
var parentRow = $(this).parents('.partial-enclosing-class');
var hiddenInput = parentRow.find('input[name$="].Id"]');
var formPrefix = hiddenInput.prop('name').replace(".Id", "");