Post to WebAPI and ODATA resulting in multiple posts

2 posts, 0 answers
  1. CM
    CM avatar
    12 posts
    Member since:
    Nov 2012

    Posted 28 Jun 2015 Link to this post

    Hey everyone,

    I have an issue with my Data Source that when I post, it's not updating the Data Source's entity with the new ID that is created on the server side. What then happens, is any other post I make sends multiple posts. The second time I post, it sends two posts, the third time, three posts, etc. I have look through the forum post here:

    And I'm having the same issue. I am returning the Id of the newly inserted record, and it's even saving out to the SQL data base.

    I'm using ASP.NET WebAPI Odata controllers. The controller looks like this:

    // POST: odata/Actions
    public IHttpActionResult Post(TNYData.Action action)
          if (!ModelState.IsValid)
            return BadRequest(ModelState);
          action.Created = DateTime.Now;
          action.CreatedBy = User.Identity.Name;
          action.Modified = DateTime.Now;
          action.ModifiedBy = User.Identity.Name;
          return Created(action);

    The Data Source looks like this:

    actionDataSource: new{
          type: "odata-v4",
          autoSync: true,
          transport: {
            read: {
              url: config.apiBasePath + "Actions",
              dataType: "json"
            create: {
              url: config.apiBasePath + "Actions",
              dataType: "application/json",
              beforeSend: function(req) {
                req.setRequestHeader('Authorization', sessionStorage.getItem("tnyApiKey"));
          schema: {
            model: {
              id: "Id",
              fields: {
                  Id: {
                  //this field will not be editable (default value is true)
                  editable: false,
                  // a defaultValue will not be assigned (default value is false)
                  nullable: true
                Name: {
                  validation: { required: true }
                Description: {
                  validation: { required: false }

    The response JSON look like this:

      "odata.metadata":"http://localhost:64533/odata/$metadata#Actions/@Element","Id":367,"Name":"New Item","Description":null,"Created":"2015-06-28T19:37:14.9379909-04:00","Modified":"2015-06-28T19:37:14.9379909-04:00","CreatedBy":null,"ModifiedBy":null,"StartDate":null,"DueDate":null,"Flagged":false

    I get no errors in Chrome console, IE, or Visual Studio.

    What am I missing here?

  2. Rosen
    Rosen avatar
    3215 posts

    Posted 01 Jul 2015 Link to this post

    Hello CM,

    Unfortunately, I do not see anything suspicious in the code snippets you have provided. Therefore, it will be appreciated if you could provide a small runnable sample which demonstrates the issue.

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top