This project has moved. For the latest updates, please go here.

Problems Posting to WebAPI method

Apr 23, 2012 at 4:19 PM

I have found various posts about how to replace the default JSON implementation with and I am able to retrieve items from the database.  I am trying to post a Javascript object to a WebAPI method now and have it resolve to a model class that I have defined in my project.  I keep running into the same exception: Error reading integer. Unexpected token: StartObject. Line 1, position 1.  Some assistance with this would be very much appreciated!

May 1, 2012 at 11:02 AM

I have the same issue. How did you solve the problem?

May 1, 2012 at 7:17 PM
Edited May 1, 2012 at 7:18 PM

For me it was not realizing that I was not using the correct parameters in the POST method in my ApiController.  I was trying to have serialize an object to a parameter in my method that was an Int value.

Had this as my method before that didn't work and I couldn't figure out why it was trying to serialize to an Int:

public HttpResponseMessage<NewsCategory> Post(int employee, NewsCategory category) { ...  code to save to database ... }

Changed the method to this and was able to successfully post to the database.

public HttpResponseMessage<NewsCategory> Post(NewsCategory category) {... code to save in the database ...}

Hope that this helps. Please feel free to respond back with some code if you need some further help.