Delete a record from a Edit Page

Good afternoon,

I was wondering if there is an elegant way to delete a record from an edit page of a record?

I am using JSRuntime to display a confirmation box, then firing a custom method to delete the record which returns true if successful, the closes the dialog. However, the grid doesn’t refresh. I’m guessing it’s because the close dialog service doesn’t see a change in the returned object.

public partial class EditCountryCodeComponent
    {
        [Inject]
        public Data.MyDbContext context { get; set; }

        async Task<bool> Confirm(string message)
        {
            var result = await JSRuntime.InvokeAsync<bool>("confirm", new[] { message });
            return result;
        }

        public bool DeleteRecord(int id)
        {
            try
            {
                var item = context.CountryCodes.Find(id);
                context.Remove(item);
                context.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                string error = $"Error: {(ex.InnerException != null ? ex.InnerException.Message : ex.Message)}";
                throw new Exception(error);
            }
        }
    }

image

Is there a better way to do what I’d like to do here? This also feels heavy work to roll this out across all my Edit pages. Hoping to find something a little more reusable if possible?

PS, sorry for the duplicate post, I left the client name in the code!

You can probably use the deleteXXX data source method that has been generated by Radzen (via the Invoke DataSource method action).

Also you can probably use the confirm as Condition: