Hi Guys,
I have the following action on a controller:
[HttpPost]
public ActionResult SaveSubmission(SubmissionModel submission, SubmissionStateEnum submissionState)
{
if (Request.IsAjaxRequest())
{
return Json(true, JsonRequestBehavior.AllowGet);
}
return RedirectToAction("Index");
}
The submission model looks as follows:
[Serializable]
public class SubmissionModel
{
public string TestString { get; set; }
public SubmissionDetailsModel Details { get; set; }
public SubmissionIncomeStatement IncomeStatement { get; set; }
public SubmissionSubcontractorModel SubcontractorDetails { get; set; }
public SubmissionModel()
{
TestString = "NEW";
Details = new SubmissionDetailsModel();
IncomeStatement = new SubmissionIncomeStatement();
SubcontractorDetails = new SubmissionSubcontractorModel();
}
}
On my page, I have this function to submit the data:
function SaveSubmission() {
var sd = { MarketId: 2, SubmissionDate: $('#submissionDate').attr('data-date') };
var so = {
TestString: 'fromPage',
Details: sd,
IncomeStatement: null,
SubcontractorDetails: null
};
$.ajax({
type: "POST",
url: '@Url.Action("SaveSubmission")',
data: { submission: JSON.stringify(so), submissionState: '@SubmissionStateEnum.Rejected' },
dataType: "json",
success: function (data) {
alert(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR);
alert(textStatus);
alert(errorThrown);
}
});
}
The problem I am having is that when the action gets called from the ajax the "submission" parameter is null, however if I look at the request I can see it has passed the data back.
So my question is why is it not mapping to my object on the action? I've tried serialisation and I cannot seem to get it to work? I might be missing something very obvious but I have no idea what it is.
If you need more info, please ask.
Thanks in advance.