I am currently working on an mvc3 project and encountering issues with sending an ajax post request from my JS code. The problem lies in the fact that I am receiving an internal error, and upon debugging, I noticed that the method is not being invoked.
Below is my JS code snippet:
ajaxCallTest: function (url, dataObj) {
$.ajax({
url: url,
type: "POST",
data: dataObj,
success: function (result) {
}
,
error: function (result) {
}
});
}
And here is my C# code snippet:
[HttpPost]
public string Transaction(PaymentModel model)
{
...
}
Upon testing using the following lines of code:
ajaxCallTest('..url/Transaction', ''); <- enters 'Transaction' with null values...
However, when I run:
ajaxCallTest('..url/Transaction', model); <--- the model is of type PaymentModel
The second code does not trigger the 'Transaction'
method, instead resulting in a 500 internal error message.
Can anyone shed some light on why this might be happening?
Edited:
var dataObj = { Id: 11, Description: "hh" };
$.ajax({
url: url,
type: "POST",
data: JSON.stringify(dataObj),
success: function (result) {
//window.location.replace(result);
var form = $(result);
$(form).submit();
}
,
error: function (result) {
console.log('Error ' + result);
//cardStrip.fail();
}
});