I need to save the record in the database. I have been doing this thing but I don't know for what reason it is giving me this error. Any help will be appreciated. I don't know why the data is null. Please refer to the error show in below screenshot:
data is not defined
function submit(amount) {
var _url = ' /Home/SaveDepositedAmount';
console.log(_url);
$.ajax({
type: "POST",
async: false,
cache: false,
beforeSend: function () { ShowLoading(); },
url: _url,
processData: false,
contentType: false,
dataType: 'json',
data: { amount: amount },
})
.done(function (data) {
Server side code is:
[HttpPost]
public JsonResult SaveDepositedAmount(int amount)
{
JsonResult result = new JsonResult();
int userId = Authentication.Instance.User.UserId;
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
}
You’re passing an object through to the server side but it’s only expecting an int. Create an object with 1 property (int Amount) and use that instead of the int for your server side parameter
Pass the amount in the url itself
var _url = ' /Home/SaveDepositedAmount?amount='+amount
Also remove the data
from the $.ajax
method