-1

How to get the Partial View object on form submit

Main View:

@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>
}

Creative Partial View:

<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>

My Controller Action:

[HttpPost]
public ActionResult SubmitForm(CreateCampaignModel createCampaignModel)
{
  return (View(BindCampaignModel()));
}

I want to return the campaignCreativeModel object to the controller with all the collections of partial views inside partial views.

My Main Model:

public class 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; }

}

My model have all the collections related to partial views in the main view.

Screenshot:

enter image description here

Kapil
  • 1,823
  • 6
  • 25
  • 47
  • You have multiple issues. First your model has only fields and the `DefaultModelBinder` will not bind fields, only properties. Your generating duplicate `id` attributes which is invalid html. But what is it that your actually wanting to submit? And what is the model in the main view. And what is the 'main' model you have shown? –  Aug 02 '16 at 04:12
  • Do you at least get this displaying? And then your question is how do you get the submit button to post back all your data? – Worthy7 Aug 02 '16 at 05:19
  • My Design is loding perfect and I can do individual operation on the partial views ...I havent put the complete design its very big @Worthy – Kapil Aug 02 '16 at 05:53
  • And what properties are you trying to bind to (sorry to be harsh, but nothing makes any sense, and it certainly wont work) –  Aug 02 '16 at 05:59
  • I am binding all the properties mentioned in the CreateCampaignModel model – Kapil Aug 02 '16 at 06:10
  • [HttpPost] public ActionResult SubmitForm(CreateCampaignModel createCampaignModel) { return (View(BindCampaignModel())); } Did you debug into this function? – Worthy7 Aug 02 '16 at 06:15
  • Yes I debug but the object is Empty. – Kapil Aug 02 '16 at 06:21
  • Well that's a good start, so can you confirm what is actually being sent from your browser please, or use VS's debugging tools to see the request come in and with what data. I am trying to see if this is a binding problem, or if you are not sending the data properly – Worthy7 Aug 03 '16 at 05:07

1 Answers1

0

I haven't gone through your code completely

[HttpPost]
public ActionResult SubmitForm(list<CreateCampaignModel> createCampaignModelList)
{
  return (View(BindCampaignModel()));
}

this is the idea, you can get collection,if you are building the partial view from the model, I haven't tested the code..

Arun Prasad E S
  • 9,489
  • 8
  • 74
  • 87