Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7613085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:04:49+00:00 2026-05-31T02:04:49+00:00

Data sent from client will not get deserialized. Client: $.ajax({ type: ‘POST’, dataType: json,

  • 0

Data sent from client will not get deserialized.

Client:

$.ajax({
     type: 'POST',
     dataType: "json",
     url: 'savecommentsservice',
     data: { "Pid": 0, "Comments": [{ "User": "bbbbbb", "Text": "aaaaaaaa" }, { "User": "ddddddd", "Text": "ccccccccc"}] },

DTO:

public class Comment
{
    public string User { get; set; }
    public string Text { get; set; }
}
public class SaveCommentsRequest
{
    public int Pid { get; set; }
    public string SiteId { get; set; }
    public string Column { get; set; }
    public List<Comment> Comments { get; set; }
}

Server:

Routes.Add<SaveCommentsRequest>("/savecommentsservice");

...

public object Execute(SaveCommentsRequest request)
    {
        // Why is request.Comments null !!! All other params of the request works fine

        // THe string I'm putting in is generated below - just to make sure its correct
        request.Comments = new List<Comment>();
        request.Comments.Add(new Comment { Text = "aaaaaaaa", User = "bbbbbb" });
        request.Comments.Add(new Comment { Text = "ccccccccc", User = "ddddddd" });

        var thisIsWhatIPutInto$AjaxCall = JsonSerializer.SerializeToString<SaveCommentsRequest>(request);

Any Idea what’s wrong? Why is the Comments array not populated. As you can see from the comments I’ve generated the string with the servicestack json serializer.

Maybe I’m missing some obvisous here?

EDIT
When looking at fiddler whats beeing transmitted I see this:

    POST http://localhost:4920/savecommentsservice HTTP/1.1
Host: localhost:4920
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: zh,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:4920/default.cshtml?viewId=3
Content-Length: 227
Cookie: ASP.NET_SessionId=slbw453revfgmwuuxyrim1an
Pragma: no-cache
Cache-Control: no-cache

SiteId=Site1&Pid=0&Column=C6&Comments%5B0%5D%5BUser%5D=bbbbbb&Comments%5B0%5D%5BText%5D=aaaaaaaa&Comments%5B1%5D%5BUser%5D=ddddddd&Comments%5B1%5D%5BText%5D=ccccccccc&Comments%5B2%5D%5BUser%5D=ggggggg&Comments%5B2%5D%5BText%5D=

And in firebug:

    Parametersapplication/x-www-form-urlencoded
Column  C6
Comments[0][Text]   aaaaaaaa
Comments[0][User]   bbbbbb
Comments[1][Text]   ccccccccc
Comments[1][User]   ddddddd
Comments[2][Text]   
Comments[2][User]   ggggggg
Pid 0
SiteId  SiteId0
Source
SiteId=SiteId0&Pid=0&Column=C6&Comments%5B0%5D%5BUser%5D=bbbbbb&Comments%5B0%5D%5BText%5D=aaaaaaaa&Comments%5B1%5D%5BUser%5D=ddddddd&Comments%5B1%5D%5BText%5D=ccccccccc&Comments%5B2%5D%5BUser%5D=ggggggg&Comments%5B2%5D%5BText%5D=

Regards

Larsi

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:04:50+00:00Added an answer on May 31, 2026 at 2:04 am

    As you can see by default jQuery’s Ajax submits it as ‘application/x-www-form-urlencoded’ which is the default HTML Form Post Content-Type. Unfortunately it doesn’t handle nested objects very well and ServiceStack will expect nested objects in the JSV Format.

    So for complex types / nested objects you want to tell jQuery to send the request as JSON which you can do by specifying the contentType:application/json parameter e.g:

    var data = { "Pid": 0, "Comments": [{ "User": "bbbbbb", "Text": "aaaaaaaa" }]};
    $.ajax({
         type: 'POST',
         dataType: "json",
         contentType: "application/json",
         url: 'savecommentsservice',
         data: JSON.stringify(data)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a PHP page with data sent from MySQL. Is it better to
I have a form that is capturing data sent from a google LocalSearch API.
I want to shrink the data that is sent back and forth via AJAX,
I am regularly required to compare data sent to me in Excel spreadsheets with
How can I effectively trace the raw data sent to my socket server listening
Is there a way to check the data sent by a form to a
I am interfacing with a server that requires that data sent to it is
I've got a web application that, for performance reasons, throws any data sent into
I sent a multi-line data with length greater than 20. I'm sure of this
I'm designing an application that reads data to the iPod touch/iPhone that is sent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.