I have a jQuery function as this:
$.ajax({
type: "POST",
url: "/Accounting/Journal/SaveModal",
data: varData,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (e) {
alert(e);
},
error: function (e, ex) {
$("div#divModalBody").modal('toggle');
alert(ex);
},
complete: function (e) {
$("div#myLoadingDialog").modal('toggle');
$("div#myModal").modal('toggle');
}
});
and my SaveModal action is :
//######################### SaveModal (POST) #########################
[System.Web.Mvc.HttpPost]
[Infrastructure.ProjectActionPermission
(isVisibleJustForProgrammer: false,
accessType: Models.Enums.AccessTypes.Special,
keyName: Resources.Strings.ActionsKeys.Save)]
public virtual System.Web.Mvc.JsonResult SaveModal
(System.Guid journalheaderid, System.Guid account, System.Guid center1,
System.Guid center2, System.Guid center3, System.Guid project, string description,
decimal debit, decimal credit, string number, int quantity, int shamsid, int shamsim, int shamsiy)
{
Models.Accounting.JournalDetail oJournalDetail =
new Models.Accounting.JournalDetail();
if (ModelState.IsValid)
{
// **************************************************
if ((shamsid != 0) &&
(shamsim != 0) &&
(shamsiy != 0))
{
oJournalDetail.Date =
Dtx.Calendar.Convert.PersionToCivil
(shamsiy, shamsim, shamsid);
}
// **************************************************
oJournalDetail.JournalHeaderId = journalheaderid;
oJournalDetail.AccountId = account;
if (center1 != System.Guid.Empty)
{
oJournalDetail.Center1Id = center1;
}
if (center2 != System.Guid.Empty)
{
oJournalDetail.Center2Id = center2;
}
if (center3 != System.Guid.Empty)
{
oJournalDetail.Center3Id = center3;
}
if (project != System.Guid.Empty)
{
oJournalDetail.ProjectId = project;
}
oJournalDetail.RowDescription = description;
oJournalDetail.Debit = debit;
oJournalDetail.Credit = credit;
oJournalDetail.Number = number;
oJournalDetail.Quantity = quantity;
oJournalDetail.IsPending = true;
// **************************************************
oJournalDetail.SetInsertDateTime
(Infrastructure.Sessions.AuthenticatedUser.Id);
oJournalDetail.SetIsActive
(oJournalDetail.IsActive,
Infrastructure.Sessions.AuthenticatedUser.Id, Infrastructure.Utility.Now);
// **************************************************
UnitOfWork.AccountingUnitOfWork.JournalDetailRepository.Insert(oJournalDetail);
UnitOfWork.Save();
}
// **************************************************
ViewBag.ShamsiD =
new System.Web.Mvc.SelectList
(Dtx.Calendar.Day.Days, "Value", "Text", oJournalDetail.ShamsiD);
ViewBag.ShamsiM =
new System.Web.Mvc.SelectList
(Dtx.Calendar.Month.Months, "Value", "Text", oJournalDetail.ShamsiM);
ViewBag.ShamsiY =
new System.Web.Mvc.SelectList
(Dtx.Calendar.ShamsiAccountingYear.Years, "Value", "Text", oJournalDetail.ShamsiY);
// **************************************************
var varJsonResult =
Json(new { oJournalDetail },
System.Web.Mvc.JsonRequestBehavior.AllowGet);
ViewBag.JournalDetail = oJournalDetail;
return (varJsonResult);
}
//######################### SaveModal (POST) #########################
but when I run my code after filling form , I expect to see my object but I saw undefined. I completely confused and I don't know what is my mistake?
What must I do know?
successevent handler runs, and inspect the variablee. Debug the c#, check if the action actually runs and returns something.