We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

ASP.NET MVC Grid - columns not updated after Edit->Put / ODATA / EF

Hi, I am trying to get it to work with the controller generated by visual studio for ODATA V3 and EF. The grid initially renders well and shows all data.

This is the code for Put. After a successful Put my record gets updated and code 204 is returned as far as I know. But no data is returned and the grid is not updated to the change. How can I get the grid updated after the put? A page reload shows the correct grid.

Controller:

       // PUT: odata/TodoItems(5)

        public IHttpActionResult Put([FromODataUri] string key, Delta patch)

        {

            Validate(patch.GetEntity());

            TodoItem todoItem = db.TodoItems.Find(key);

            if (todoItem == null)

            {

                return NotFound();

            }

            patch.TrySetPropertyValue("CreatedAt", todoItem.CreatedAt);

            patch.Put(todoItem);

                db.SaveChanges();

 

            return Updated(todoItem);

        }


Grid:

   @Html.EJS().Grid("OData").DataSource(dataManger =>

 {

     dataManger.Url("/odata/TodoItems").CrossDomain(true).Adaptor("ODataAdaptor");

 })....


3 Replies

HJ Hariharan J V Syncfusion Team May 22, 2019 04:07 PM UTC

Hi Andreas, 
  
Thanks for contacting Syncfusion support. 
  
We have analyzed your query and the codes which you have shared with us. We suspect that the problem is with the way you are returning the result from the server side “Put” method. We suggest you to return the result from the server side method as a Json. Please refer the code example below, 
  
        // PUT: odata/Products(5) 
        public IHttpActionResult Put([FromODataUri] int key, Delta<Product> patch) 
        { 
            .  .  . 
            return Json(product);     //Return as Json 
        } 
  
  
And also we suggest you to ensure whether you have provided “isPrimaryKey” for a column in Grid, as based on the primary key column only, the CRUD actions will take place. 
Documentation : 
  
If you are still facing the problem, please get back to us with the following details, 
  1. Share the full Grid code.
  2. Share the screenshot of the post from the network tab.
  
Please get back to us if you need further assistance. 
  
Regards, 
Hariharan 



AN Andreas May 22, 2019 07:08 PM UTC

Hariharan,

Thanks a lot! Your proposed solution works like charme. Wouldnt it be good to mention this in the documentation. Its really hard to figure out.

return Json(product);     //Return as Json 

Thanks you so much,
Andreas


HJ Hariharan J V Syncfusion Team May 23, 2019 10:48 AM UTC

Hi Andreas, 
  
Thanks for your update. 
  
We are happy to hear that your issue has been resolved. And we have logged this scenario in our documentation task and which will available in any of our upcoming releases. 
  
Regards, 
Hariharan 


Loader.
Live Chat Icon For mobile
Up arrow icon