After rummaging through the documentation, I found where it shows an example on how to "Persist data in the server" as it relates to Batching. However, the example uses a UrlAdapter rather than an ODataV4Adapter. I'm not able to create a controller method that binds correctly for the action.
Here is an example of what the frontend is trying to call:
And here is an example of my backend controller action that works (without the body):
[HttpPost("queryodata")]
public IActionResult BatchOData(ODataQueryOptions<dynamic> options, int gridId, Guid? instanceId, int userId = 1)
{
return Ok();
}How would I need to alter the controller action to accept the body or "changes" being posted?
I tried adding a "[FromBody] object contents", to the parameter listing but it would not bind properly.
Thanks,
- JV
Hi Jeff,
Thanks for contacting Syncfusion support.
The ODataV4Adaptor is used to fetch the data from Odata standard services. Kindly refer to the below documentation for more information.
OdataV4Adaptor: https://ej2.syncfusion.com/react/documentation/grid/data-binding/remote-data/#odata-v4-adaptor---binding-odata-v4-service
|
public gridData: DataManager = new DataManager({ url: "/odata/Books", adaptor: new ODataV4Adaptor() });
|
By default, If we use ODataV4Adaptor, the GET method will be triggered for all the grid actions like Paging, Sorting, Filtering, etc., The POST, PATCH, DELETE methods will be triggered for CRUD actions like insert, edit, delete respectively. In these methods, you can perform the CRUD actions in your service.
Screenshot: payload on CRUD actions
|
|
|
namespace Batch_OdataV4_Core.Controllers { [Route("api/[controller]")] public class BooksController : ODataController { private BookStoreContext _db;
public BooksController(BookStoreContext context) { _db = context; if (context.Books.Count() == 0) { foreach (var b in DataSource.GetBooks()) { context.Books.Add(b); } context.SaveChanges(); }
} // GET api/values [HttpGet] [EnableQuery] public IQueryable<Book> Get() { return _db.Books; }
// POST api/values [HttpPost] [EnableQuery] public IActionResult Post([FromBody]Book book) { _db.Books.Add(book); _db.SaveChanges(); return Created(book); }
[System.Web.Http.AcceptVerbs("PATCH", "MERGE")] public Book Patch(int key, [FromBody]Delta<Book> patch) { var query = Request.Headers["params"]; var entity = _db.Books.Find(key); patch.Patch(entity); _db.SaveChanges(); return entity; }
// DELETE api/values/5 [HttpDelete("{id}")] public async Task<int> Delete(int key) { var od = await _db.Books.FindAsync(key);
_db.Books.Remove(od); await _db.SaveChangesAsync(); return key; } } }
|
If you want to bind SQL data or List type of data to the Grid, you can use URL Adaptor data-binding for this.
URL Adaptor: https://ej2.syncfusion.com/react/documentation/grid/editing/persisting-data-in-server/#using-url-adaptor
Please get back to us if you need further assistance.
Regards,
Rajapandiyan S