TL;DR: I just need to figure out why i can't serialize() the partial view's parent div and receive the model. Coding this out manually will take forever as there are many parent partials I'd have to use the same logic on.
More info: I've tried EditorTemplate for binding purposes, but unfortunately there is no easy way to use them as variable lists as far as I've searched.
Begin:
Models
public class ContactModel
{
public List<ContactDetailModel> Contacts { get; set; }
....
public class ContactDetailModel
{
public ContactView Contact { get; set; }
public PhoneModel PhoneModel { get; set; }
...
public class PhoneModel
{
public int ContactId { get; set; }
public int IsPrimaryPhoneNumberId { get; set; }
public List<PhoneView> Phones { get; set; }
public List<EmailPhoneTypeView> EmailPhoneTypes { get; set; }
...
To select & post inputs from just this partial view, I've implemented a variable class, and its relative template prefix to keep the MVC binding for the partial view.
@{
var phoneClass = "phone" + @Model.Contacts[index].Contact.ContactId;
var phoneTemplatePrefix = "Contacts[" + index + "].PhoneModel";
}
This is ran inside of a loop, increasing indexes as needed to keep binding.
<div class="@phoneClass">
@Html.Partial("_ContactPhone", Model.Contacts[index].PhoneModel, new ViewDataDictionary() { TemplateInfo = new TemplateInfo() { HtmlFieldPrefix = phoneTemplatePrefix } })
</div>
The partial I'm attempting to post. (Strongly Typed partial for PhoneModel)
@{var addNavigationClass = "AddContactPhone" + Model.ContactId;}
for (var phoneIndex = 0; phoneIndex < Model.Phones.Count(); phoneIndex++)
{
@Html.HiddenFor(model => model.Phones[phoneIndex].ContactPhoneId)
@Html.DropDownListFor...
@Html.TextBoxFor(model => model.Phones[phoneIndex].PhoneNumber)
<a href="#" class="removeMemberPhone">Trash</a>
@Html.RadioButtonFor(model => model.IsPrimaryPhoneNumberId, Model.Phones[phoneIndex].ContactPhoneId) Primary</label>
}
Inside the View's click function
var model = $('.phone' + '@Model.ContactId' + ' :input').serialize();
console.log('model', model);
$.ajax({
url: '/Contact/AddPhone',
type: 'POST',
data: model,
success: function (data) {
console.log(data.length);
}
....
The log's output
model Contacts%5B1%5D.PhoneModel.Phones%5B0%5D.ContactPhoneId=3907&Contacts%5B1%5D.PhoneModel.Phones%5B0%5D.EmailPhoneTypeId=1&..........
My model never has any values in my controller (I've abbreviated ContactPhoneModel to PhoneModel in the above code)...

EditorTemplatesnot partials to ensure your form controls are correctly named. Your view appears to be based onContactModelbut you posting backContactPhoneModelso the names of your form data do not match the names of your model properties so it cannot be boundpublic PhoneModel PhoneModelbut I assume that's supposed to bepublic ContactPhoneModel PhoneModel?EditorTemplateswon't work for the variable type list I'm implementing with this view. Also I'm aware of the Model name differences I've tried to abbreviate them, and wil edit the post to fix them.EditorTemplate. The model in your view isContactPhoneModelwhich mean your form data needs to beContactPhoneId=3907notContacts[1].PhoneModel.Phones[0].ContactPhoneId=3907which would never work anyway since indexers must start at zero and be consecutive.phoneModel(recommended on many of the stack's posts, is the partial view). The log returnedContacts[1]as it is the second contact that i clicked on to add thephoneModeltoo.