This is a migrated thread and some comments may be shown as answers.

[Solved] Row not returned after insert with WebAPI

2 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wim
Top achievements
Rank 1
Wim asked on 17 Oct 2014, 12:03 PM
When using inline editing in the Grid, all entries are added again for each new row I add. I've tracked this down and it seems to be caused by not returning the inserted row to the Grid, which is why the ID stays 0 and every row is treated as a new row each time.

I've tried to solve this, but even using the example from the docs, I can't get it to work.

My grid uses this WebAPI call to insert a row. How should I change it to return the row correctly, including the ID?


public HttpResponseMessage Post(Batch model)
{
    HttpResponseMessage response;
 
    if (ModelState.IsValid) {
        service.Create(model.ReceiptLineURID, model);
 
        DataSourceResult result = new DataSourceResult {
            Data = new[] { model },
            Total = 1
        };
 
        response = Request.CreateResponse(HttpStatusCode.Created, result);
        response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = model.BatchNo }));
    } else {
        response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
    }
 
    return response;
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 21 Oct 2014, 08:45 AM
Hello Wim,

Could you please confirm that you actually have the updated item when returning the response from the server. In other words if you have the same as the example like ours:

service.Create(model.ReceiptLineURID, model);
  
-> Could you please confirm that model.Id at this point is different than 0? <-
        DataSourceResult result = new DataSourceResult {
            Data = new[] { model },
            Total = 1
        };

If it is then it should mark the created item as successfully updated. In case still the client side sends the record for creation and the model is actually updated we will need a small sample project or a LIVE URL to visit and investigate on.

Kind Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Wim
Top achievements
Rank 1
answered on 21 Oct 2014, 11:17 AM
The ID was indeed 0, once I made sure it was set to the new value, everything worked as expected. Thank you!
Tags
Grid
Asked by
Wim
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Wim
Top achievements
Rank 1
Share this question
or