I'm having a problem with posting a view that has multiple partial views within it using one submit button
This is my A model,
:UPDATED:
public class AModel
{
public int AID { get; set; }
public int BID { get; set; }
public int CID { get; set; }
public int ANumber { get; set; }
public BModel BModel { get; set; }
public CModel CModel { get; set; }
}
this is my B model
public class BModel
{
public int BID { get; set; }
public int BName { get; set; }
public IList<DModel> DModel { get; set; }
}
this is the D model
public class DModel
{
public int DID { get; set; }
public int? Number { get; set; }
}
this is the c Model
public class CModel
{
public int CID { get; private set; }
public IList<HModel> HModels { get; set; }
}
and so on this is the main view
@model Project.Web.Models.AModel
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.Partial("CreateB",Model.BModel);
@Html.Partial("CreateC",Model.CModel);
<input style="border-radius:4px;width:100px;" type="button" value="next" id="next" class="btn btn-default" />
}
this is the Get action
public ActionResult Create(){
Models.AModel model = new Models.AModel(){
BModel = new BModel(){
DModel = new List<Models.DModel>(){ new Models.DModel() },
CModel = new CModel(){
HModel = new List<HModel>(){ new Models.HModel() },
};
return View(model);
}
this is the Post action
[HttpPost]
public ActionResult Create(Models.AModel model)
{
//doing things with data
//when I reach this point all object are null
return RedirectToAction("index", model);
}
public void SetNumber(Models.BModel model){
model.DModel.Add(new Models.DModel());
}
Partial View For BModel, and CModel is similar to BModel Partial view Note: the SetNumber method only create a new Object and add it to the list
@model Project.Web.Models.BModel
@Html.TextBoxItemFor(x => x.BName)
@for ( int i=0; i< Model.DModel.Count; i++){
@Html.TextBoxItemFor( x => x.DModel[i].Number)
<a id="addNumber" href="/AController/SetNumber/" data-ajax="true" data-
ajax-method="GET" >Add Another Number</a>
}
What can I do? What Am I missing?