'Jquery Ajax Not Passing Data to MVC Controller
I am using jquery's ajax method to submit data to a MVC controller. However, no data is passed to the controller. I have tried altering the parameter expected by the controller to a string and the object expected. When it is a string null is passed and when it is an object an empty object is created.
The code below speaks for its self, but as a brief explanation I am creating a javascript object with customer data and stringifying that as part of the ajax call.
I know there are previous posts on this, which I've followed but with no success.
Any help greatly appreciated.
var data = {
id: _CustomerID,
Address1 : _Address1,
Address2 : _Address2,
Address3 : _Address3,
Address4 : _Address4,
PostCode : _Address5,
EmailAddress : _Email,
PhoneNumber : _Phone,
postemail: _postemail,
postonly: _postonly,
emailonly: _emailonly
}
url = '@Url.Action("UpdateContactDetails", "MyAccount")';
$.ajax({
type: "POST",
dataType: "json",
data: JSON.stringify({CustomerObj: data}),
url: url,
contentType: "application/json"
}).done(function (res)
{
//process result
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
