1

I have a game object in client side JavaScript that looks like this right before being sent to the server:

Client Side

Here it is server side a second later, note all the properties are filled, and the Questions list is populated with the correct number of question, however the properties of each question are null, whereas on the client side they had the correct values.

Server Side

Here is the code for the models:

public class Game
{
    public Game()
    {
        Questions = new List<Question>(5);
    }
    public int GameID { get; set; }
    public Guid UserID { get; set; }
    public Guid CurrentGameID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public IEnumerable<Question> Questions { get; set; }
}

public class Question
{
    public int ID { get; set; }
    public string Text { get; set; }
    public IEnumerable<int> Answers { get; set; }
    public int SelectedAnswer { get; set; }
}

And here is how I send the object back to the server:

// Send completed game back to server
$.post("Games/CompleteGame", currentGame, function (results)
{
    // display results to user
}
2
  • 3
    Can you show the raw JSON being sent in the POST? Also, can you verify the content-type? Commented Apr 12, 2013 at 21:34
  • @Ek0nomik I'm not sure how to get the raw JSON in this case. Commented Apr 12, 2013 at 21:43

1 Answer 1

1

Based on Ek0nomik's comment asking about the content-type, I rewrote my ajax call to set contentType to json:

$.ajax(
    {
        url: "Games/CompleteGame",
        type: "POST",
        data: JSON.stringify(currentGame),
        contentType: "application/json",
        success: function (results)
        {
            // show results to user...
        }

As it turns out, this was all it needed to make it work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.