I've got main model like this
public class MainModel
{
public Child1 Child1 { get; set; }
public Child2 Child2 { get; set; }
public Child3 Child3 { get; set; }
public Child4 Child4 { get; set; }
}
These all are rendered as follows:
<form id="MainForm">
@Html.Partial("~/Views/Child1.cshtml", Model.Child1)
@Html.Partial("~/Views/Child2.cshtml", Model.Child2)
@Html.Partial("~/Views/Child3.cshtml", Model.Child3)
@Html.Partial("~/Views/Child4.cshtml", Model.Child4)
</form>
I'm trying to post mainform and the action method looks like this
[HttpPost]
public ActionResult Save(MainModel obj)
{
}
Everytime each object (Child1, Child2 etc.) are null. I'm posting form via AJAX as follows:
$.ajax({
url: '@Url.Action("Save","SaveController")',
type: "POST",
data:$("#MainForm").serialize(),
success: function (data) {
}
});
Am i missing something? Is there any other way i can process data? I can not have multiple submits on partial views that's the constraint here.
Any suggestions please.