Hello Team,
Please this is a simple ajax code I thought could work but fail to save the data into the database, kindly assist me please
function saveSalary() {
var model = {};
model.SalaryId = $("#salaryId").val();
model.PayDate = $("#date1").val();
model.Name = $("#name").val();
model.Advance = $("#advance").val();
model.Month = $("#month").val();
model.FinalPay = $("#finalsalary").val();
model.PayBy = $("#by").val();
var data = JSON.stringify({
model: model
});
swal("Save!", "Salary save successfully", "success");
$("#success-message").click(function (e) {
Swal.fire({
title: "Good job!",
text: "You clicked the button!",
icon: "success",
buttonsStyling: false,
confirmButtonText: "Confirm me!",
customClass: {
confirmButton: "btn btn-primary"
}
});
});
return $.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: '/Home/SaveSalary',
data: data,
sucess: function (result) {
if (result == true) {
Reset();
getAllSalary();
dataTable-Salary.ajax.reload();
$("#SalaryModal").modal('hide');
}
else {
swal("Save Fail");
}
},
error: function () {
swal("Error!");
}
});
}
ENTITY DATA CLASS
public class SalaryViewModel
{
public int SalaryId { get; set; }
public string PayDate { get; set; }
public string Name { get; set; }
public Nullable<decimal> Advance { get; set; }
public string Month { get; set; }
public Nullable<decimal> FinalPay { get; set; }
public string PayBy { get; set; }
}