如何在表单提交上获取部分视图对象
主要观点:
@model CreateCampaignModel
....
@using (Html.BeginForm("SubmitForm", "Campaign", FormMethod.Post))
{
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse2">Step 2: Creative*</a>
</h4>
<a style="padding-left:90%;" id="lnkEdit">Edit</a>
</div>
@Html.EditorFor(m => Model.campaignCreativeModelList[0])
@foreach (var m in Model.campaignCreativeModelList)
{
<div id="collapse2" class="panel-collapse collapse">
@Html.Partial("~/Views/Campaign/_Creative.cshtml", m)
</div>
}
</div>
}
广告素材部分视图:
<div class="panel-body">
<div class="form-group">
@Html.Partial("~/Views/Shared/_ImageVideoUploadView.cshtml", Model.socialJobMediaModel)
</div>
<div class="col-md-10">
<div class="editor-field">
<input type="submit" name="Save Group" value="Review and Submit" class="btn btn-primary" />
</div>
</div>
</div>
我的控制器操作:
[HttpPost]
public ActionResult SubmitForm(CreateCampaignModel createCampaignModel)
{
return (View(BindCampaignModel()));
}
我想将campaignCreativeModel
对象返回给控制器,并在局部视图中包含部分视图的所有集合。
我的主要模特:
公共类CreateCampaignModel {
public List<CampaignCreativeModel> campaignCreativeModelList { get; set; }
public List<ClientAccountCampaignBundlesModel> clientAccountCampaignBundlesModelList { get; set; }
public List<CampaignBundleSchedulesModel> campaignBundleSchedulesModelList { get; set; }
public List<CampaignConfigurationModel> campaignConfigurationModelList { get; set; }
public CampaignConfigurationModel campaignConfigurationModel { get; set; }
}
我的模型在主视图中包含与部分视图相关的所有集合。
屏幕截图:
答案 0 :(得分:0)
我还没有完全看清你的代码
[HttpPost]
public ActionResult SubmitForm(list<CreateCampaignModel> createCampaignModelList)
{
return (View(BindCampaignModel()));
}
这是个想法,你可以得到集合,如果你是从模型构建局部视图,我还没有测试过代码..