在ListBoxFor helper的情况下,模型绑定不起作用

时间:2019-05-15 07:31:48

标签: asp.net-mvc-4 listbox model-binding

我有以下模型

public class DealerConfiguration
{
    public List<AffiliateConfiguration> AffiliateConfiguration { get; set; }
    public DealerScopeDealerProvider DealerScopeDealerProvider { get; set; }
}

public class AffiliateConfiguration
{
    public int AffiliateConfigurationId { get; set; }
    public string Name { get; set; }
}
public class DealerScopeDealerProvider
{
    public List<DealerScopeDealer> DealerScopeDealer { get; set; }
}

public class DealerScopeDealer
{
    public int DgsAffiliateId { get; set; }
    public string BusinessName { get; set; }
}

我有一个局部视图,该视图绑定到DealerConfiguration模型,在这里我为AffiliateConfiguration和DealerScopeDealerProvider模型调用 EditorTemplates

@model DGS.DGSAPI.UI.BusinessModels.DealerConfiguration

@using (Ajax.BeginForm("EditDealerConfiguration", "Dealers", new AjaxOptions() { LoadingElementId = "loading", HttpMethod = "POST", OnSuccess = "DealerConfigSuccess(data)", OnFailure = "DealerConfigFailure" }, new { id = "DealerConfigForm" }))
{
    @Html.EditorFor(x => Model.AffiliateConfiguration)

    @Html.EditorFor(x => Model.DealerScopeDealerProvider)
}

问题是,当表单发布到我的操作方法时,它包含DealerConfiguration.AffiliateConfiguration模型,但我的DealerConfiguration.DealerScopeDealerProvider.DealerScopeDealer列表为空。

这是DealerScopeDealerProvider的 EditorTemplate

@model DGS.DGSAPI.UI.BusinessModels.DealerScopeDealerProvider

@{
    var dealers = Model.DealerScopeDealer;
}

<div class="report" id="AffiliateDropdown" margin-left:5px">
    <label class="pull-left">Dealers:</label>
    @Html.ListBoxFor(model => model.DealerScopeDealer, new MultiSelectList(dealers, "DgsAffiliateId", "BusinessName"), new { id = "filter_chkbox_div" })
</div>

我的发布操作方法如下

[HttpPost]
public virtual ActionResult EditDealerConfiguration(DealerConfiguration dc)
{}

为什么在ListBox的情况下我的绑定不起作用?

0 个答案:

没有答案