0

我有一个 PartialView 在这样调用时可以正常工作:

<div id="EmailAddresses">

    @foreach (FormEmailMessageEmailAddress toRecipient in Model.ToRecipients)
    {
        @Html.Partial("~/Views/FormEmailMessageEmailAddresses/_Edit.cshtml", toRecipient)    
    }

</div>

下一部分代码,我有一个 Ajax 调用,它返回模型并添加到 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”看起来基本上是这样的:

@model x.Models.Forms.Actions.FormEmailMessageEmailAddress

@using (Html.BeginCollectionItem(ViewData.TemplateInfo.HtmlFieldPrefix + ".ToRecipients"))
{
    @* Bunch of omitted code *@
}

从数据库条目填充 PartialView 时,Html.BeginCollectionItem 字符串看起来类似于EmailMessages[997a1db6-6205-4118-90e4-11013d8d33db].ToRecipients[780bd8fa-4121-4d45-8fbc-35f4b8fd3086],但是,当从 Ajax 函数调用时,它看起来像.ToRecipients[222a5fa2-70d6-4cac-afbc-e865b0a753be]

因为缺少前缀,控制器看不到新的集合。

使用HtmlFieldPrefixAjax 调用或其他我不正确的东西时没有信息,请让我知道您的想法,以便为我提供解决方案。

4

0 回答 0