Hi,
I have a web page which posts data to an Web API.
The ajax function is as follows.
var jsondata = { "comparisionCalculatorReq": { "transactionType": "None", "fundName": "Myfund", "annualizedReturn": "10", "frequency": "Monthly"} };
$.ajax({
type: "POST",
url: "http://localhost:1101/Mypost/PostDataAPI",
dataType: 'json',
data: jsondata
}).done(function (msg) {
alert(msg);
});
In my Web API controller i have a method as below
[ActionName("PostDataAPI")]
public string PostDataAPI(JSONdata obj)
{
try
{
string k = obj.transactionType;
return k;
}
catch (Exception err)
{
throw err;
}
}
The JSONdata class is below
public class JSONdata
{
public string transactionType { get; set; }
public string fundName { get; set; }
public string annualizedReturn { get; set; }
public string frequency { get; set; }
}
Problem is that, I'm getting null value for transactionType in my controller.
If the json data is passed like this in ajax,
var jsondata={ "transactionType": "None", "fundName": "Myfund", "annualizedReturn": "10", "frequency": "Monthly"};
then all the values are got correct.
Please provide a solution for this.
What I have tried:
I have tried making the JSONdata class as below, but still it is returning null for every values
public class JSONdata
{
public object comparisionCalculatorReq { get; set; }
public string transactionType { get; set; }
public string fundName { get; set; }
public string annualizedReturn { get; set; }
public string frequency { get; set; }
}