Hi there,
I am running into issues where the Grid is not refreshing when adding trying to perform operations on the SfGrid in my Blazor Server .NET 6 EF Core project. My page code is:
<SfGrid @ref="Grid" TValue="Organization" OnActionFailure="@GridLoadFailure" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<SfDataManager Url="api/Organization" Adaptor="Adaptors.WebApiAdaptor"></SfDataManager>
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Organization.OrganizationID) HeaderText="Organization ID" IsPrimaryKey="true" Visible="false"></GridColumn>
<GridColumn Field=@nameof(Organization.OrganizationName) HeaderText="Organization Name"></GridColumn>
<GridColumn Field=@nameof(Organization.IsBillable) HeaderText="Is Billable?"></GridColumn>
</GridColumns>
</SfGrid>And the Controller:
[Route("api/[controller]")]
[ApiController]
public class OrganizationController : ControllerBase
{
private readonly IOrganizationService _service;
public OrganizationController(IOrganizationService service)
{
_service = service;
}
// GET: api/<OrganizationController>
[HttpGet]
public async Task<object> Get()
{
return new { Items = await _service.GetOrganizationDetails(), Count = await _service.GetCount() };
}
// GET api/<OrganizationController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<OrganizationController>
[HttpPost]
public void Post([FromBody] Organization value)
{
_service.AddOrganization(value);
}
// PUT api/<OrganizationController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<OrganizationController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
_service.DeleteOrganization(id);
}
}Note, not all are implemented yet, just testing!
When Deleting, the Grid doesn't automatically Refresh. When Adding, the Update appears to work.
Is there a way to ensure the Refresh every time, or is there something fundamentally wrong with my Controller?
Thanks in advance!
Jon
Figured this out. Turns out I had an issue with the Service being Asynchronous, but I was calling it from the Controller as just a Void HttpDelete. It was executing, but the Grid was having issues refreshing, probably because of this error. All works now.
Thanks,
Jon
Hi Jonathan,
Greetings from Syncfusion.
Thanks for the update. We are happy to hear that you have found a solution to your query.
Please get back to us if you need further assistance.
Regards,
Rahul