I have a PartialView that is working properly when called like this:
<div id="EmailAddresses">
@foreach (FormEmailMessageEmailAddress toRecipient in Model.ToRecipients)
{
@Html.Partial("~/Views/FormEmailMessageEmailAddresses/_Edit.cshtml", toRecipient)
}
</div>
Next section of code, I have an Ajax call that is returning the Model and adding to the DOM:
<div class="form-group">
<div class="col-md-10" style="float: right;">
@Ajax.ActionLink(
"Add",
"AddNewEmailAddress",
null,
new { id = Model.Oid },
new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "EmailAddresses",
},
new { style = "btn btn-info" }
)
</div>
</div>
"~/Views/FormEmailMessageEmailAddresses/_Edit.cshtml" looks basically like this:
@model x.Models.Forms.Actions.FormEmailMessageEmailAddress
@using (Html.BeginCollectionItem(ViewData.TemplateInfo.HtmlFieldPrefix + ".ToRecipients"))
{
@* Bunch of omitted code *@
}
When the PartialView is populated from database entries, the Html.BeginCollectionItem string looks similar to EmailMessages[997a1db6-6205-4118-90e4-11013d8d33db].ToRecipients[780bd8fa-4121-4d45-8fbc-35f4b8fd3086]
, however, when called from the Ajax function, it looks like .ToRecipients[222a5fa2-70d6-4cac-afbc-e865b0a753be]
.
Becuase thie Prefix is missing, the Controller doesn't see the new Collection.
The HtmlFieldPrefix
doesn't have the information when using an Ajax call or something else that I have incorrect, please let me know your thoughts in pointing me towards a solution.