TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Midhun Tp
142
13.2k
1.5m
Issue with Posted JSON data to Web API
Aug 11 2016 7:11 AM
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.
Reply
Answers (
3
)
Data to be listed in a view mvc 5
Add logo image for each page on pdf file by iTextSharp