BeginCollectionItem 未绑定

BeginCollectionItem not binding

我以前使用过 Html.BeginCollectionItem() 扩展,从视图到控制器的绑定没有问题。然而,在我当前的项目中我遇到了问题。

模特

    public class EditPathViewModel : TradeContractorEscalationPath
    {
         public Guid ContractorId { get; set; }
         public List<ContactDisplayModel> Contacts { get; set; }
         public List<TradeContractorEscalationPathContact> AssignedContacts { get; set; }
         public int maxOrder { get; set; }
    }

   public partial class TradeContractorEscalationPath
   {        
       public System.Guid Id { get; set; }
       public System.Guid TradeContractorId { get; set; }
       public string Description { get; set; }
       public string Notes { get; set; }
       public System.DateTime CreatedDate { get; set; }
       public Nullable<System.DateTime> UpdatedDate { get; set; }        
   }

我正在尝试将 AssignedContacts 绑定回 Controller,它看起来像...

    [HttpPost]
    public async Task<ActionResult> EditPath([Bind(Include = "Id,TradeContractorId,Description,Notes,ContractorId,AssignedContacts,Contacts")] Models.EditPathViewModel model)
    {
        ...
    }

然而,它不断地returns null。 BeginCollectionItem 的配置如下:

TradeContractorEscalationPathContact 的编辑器模板

@model Telecare.POCO.TradeContractorEscalationPathContact

@Html.EditorFor(model => model.Order)
@Html.EditorFor(model => model.TradeContractorEscalationPathId)
@Html.EditorFor(model => model.ContactId)

调用 Assigned Contacts 集合项的视图

    ...
    <div class="col-lg-6">
        <div class="ibox-title">
            <h5>Contacts</h5>
        </div>
        <div class="ibox-content">
                @Html.EditorFor(model => model.AssignedContacts)
        </div>
    </div>
    ...

示例 HTML 来自 DOM 当 POST 被调用时

...
   <input name="AssignedContacts.index" class="ui-sortable-handle" type="hidden" value="a5895b40-2de5-4ed5-a3ed-137c047963e8" autocomplete="off">
   <input name="AssignedContacts[a5895b40-2de5-4ed5-a3ed-137c047963e8].Order" class="text-box single-line ui-sortable-handle" id="AssignedContacts_a5895b40-2de5-4ed5-a3ed-137c047963e8__Order" type="number" value="1" data-val-required="The Order field is required." data-val="true" data-val-number="The field Order must be a number.">
   <input name="AssignedContacts[a5895b40-2de5-4ed5-a3ed-137c047963e8].TradeContractorEscalationPathId" class="text-box single-line ui-sortable-handle" id="AssignedContacts_a5895b40-2de5-4ed5-a3ed-137c047963e8__TradeContractorEscalationPathId" type="text" value="0807186a-3bad-e811-9c42-8cae4cf36195" data-val-required="The Trade Contractor Path field is required." data-val="true">
   <input name="AssignedContacts[a5895b40-2de5-4ed5-a3ed-137c047963e8].ContactId" class="text-box single-line ui-sortable-handle" id="AssignedContacts_a5895b40-2de5-4ed5-a3ed-137c047963e8__ContactId" type="text" value="1e09c3ae-42ac-e811-9c42-8cae4cf36195" data-val-required="The Contact field is required." data-val="true">
   <input name="AssignedContacts.index" class="ui-sortable-handle" type="hidden" value="974a0c38-642b-40f1-a5bd-dbc4b880eaa2" autocomplete="off">
   <input name="AssignedContacts[974a0c38-642b-40f1-a5bd-dbc4b880eaa2].Order" class="text-box single-line ui-sortable-handle" id="AssignedContacts_974a0c38-642b-40f1-a5bd-dbc4b880eaa2__Order" type="number" value="2" data-val-required="The Order field is required." data-val="true" data-val-number="The field Order must be a number.">
   <input name="AssignedContacts[974a0c38-642b-40f1-a5bd-dbc4b880eaa2].TradeContractorEscalationPathId" class="text-box single-line ui-sortable-handle" id="AssignedContacts_974a0c38-642b-40f1-a5bd-dbc4b880eaa2__TradeContractorEscalationPathId" type="text" value="0807186a-3bad-e811-9c42-8cae4cf36195" data-val-required="The Trade Contractor Path field is required." data-val="true">
   <input name="AssignedContacts[974a0c38-642b-40f1-a5bd-dbc4b880eaa2].ContactId" class="text-box single-line ui-sortable-handle" id="AssignedContacts_974a0c38-642b-40f1-a5bd-dbc4b880eaa2__ContactId" type="text" value="f9d8afdd-42ac-e811-9c42-8cae4cf36195" data-val-required="The Contact field is required." data-val="true">
   <input name="AssignedContacts.index" type="hidden" value="75a5e8e5-82e1-4f58-b185-ca6abefc5d9c" autocomplete="off">
   <input name="AssignedContacts[75a5e8e5-82e1-4f58-b185-ca6abefc5d9c].Order" class="text-box single-line" id="AssignedContacts_75a5e8e5-82e1-4f58-b185-ca6abefc5d9c__Order" type="number" value="3" data-val-required="The Order field is required." data-val="true" data-val-number="The field Order must be a number.">
   <input name="AssignedContacts[75a5e8e5-82e1-4f58-b185-ca6abefc5d9c].TradeContractorEscalationPathId" class="text-box single-line" id="AssignedContacts_75a5e8e5-82e1-4f58-b185-ca6abefc5d9c__TradeContractorEscalationPathId" type="text" value="0807186a-3bad-e811-9c42-8cae4cf36195" data-val-required="The Trade Contractor Path field is required." data-val="true">
   <input name="AssignedContacts[75a5e8e5-82e1-4f58-b185-ca6abefc5d9c].ContactId" class="text-box single-line" id="AssignedContacts_75a5e8e5-82e1-4f58-b185-ca6abefc5d9c__ContactId" type="text" value="9ea0dcf8-42ac-e811-9c42-8cae4cf36195" data-val-required="The Contact field is required." data-val="true">
   <input name="AssignedContacts.index" type="hidden" value="965b81be-f52c-4055-8b4b-bccf916f14a4" autocomplete="off">
   <input name="AssignedContacts[965b81be-f52c-4055-8b4b-bccf916f14a4].Order" class="text-box single-line" id="AssignedContacts_965b81be-f52c-4055-8b4b-bccf916f14a4__Order" type="number" value="4" data-val-required="The Order field is required." data-val="true" data-val-number="The field Order must be a number.">
   <input name="AssignedContacts[965b81be-f52c-4055-8b4b-bccf916f14a4].TradeContractorEscalationPathId" class="text-box single-line" id="AssignedContacts_965b81be-f52c-4055-8b4b-bccf916f14a4__TradeContractorEscalationPathId" type="text" value="0807186a-3bad-e811-9c42-8cae4cf36195" data-val-required="The Trade Contractor Path field is required." data-val="true">
   <input name="AssignedContacts[965b81be-f52c-4055-8b4b-bccf916f14a4].ContactId" class="text-box single-line" id="AssignedContacts_965b81be-f52c-4055-8b4b-bccf916f14a4__ContactId" type="text" value="fc7a9669-43ac-e811-9c42-8cae4cf36195" data-val-required="The Contact field is required." data-val="true">
...

从我读过的所有线程来看 - HTML 看起来应该正确绑定,所以我一定是遗漏了什么或在其他地方做错了什么?有人有什么想法吗?

提前致谢

好的 - 原来我是个白痴。上面的代码确实有效,但它不具有约束力,因为它不在 @Html.BeginForm()) 部分中。叹息