0

I have a form that has a partial view (can be append multiple times) on button click with jQuery.

 $("#addPerson").on('click', function () {
      $.ajax({
           type: "POST",
           url: '@Url.Action("Partial_View")',
           success: function (res) {
               $("#personForm").append(res);
           },
           error: function (err) { console.log('err: ' + err)
       });
   });

I want the parent page to post each partial view's form data on a single submit button.

What is the best way to set up the parent/partial viewmodels and achieve this?

Let's say the repeated partial view has this model for now:

public class PartialViewModel {
    public Person Person {get; set;}
    public int PersonCount {get; set;}
}



public class Person {
    public string FirstName {get; set;}
    public string LastName {get; set;}
}
pnuts
  • 58,317
  • 11
  • 87
  • 139
Joshua Lee
  • 43
  • 1
  • 1
  • 6
  • Suggest you look at the answers [here](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308) and [here](http://stackoverflow.com/questions/40539321/partial-view-passing-a-collection-using-the-html-begincollectionitem-helper/40541892#40541892) - note for mvc-core, you need [this version](https://www.nuget.org/packages/BeginCollectionItemCore) of `BeginCollectionItem` –  May 02 '18 at 01:24
  • ty i wasn't able to find the right terms to search for this question well, these appear to be what i need – Joshua Lee May 02 '18 at 01:51

0 Answers0