Delete Automatically Created Record on Closing Browser

Dear Syncfusion,

My query is that when I click on Add button to open up a dialog form, a new record is automatically created in the database with a unique Id. However, when I click on the Close button of the browser, the record is not deleted as I want it to be deleted since that means I have not entered any data in the form. For example in the screen I am showing below: I want to delete the record with NationalizationPlanID 3.

Is there a possibility of attaining this to delete that record from the database on closure of the browser.


I have attached my razor page as NationalisationPlanPage.razor and a video demonstrating my concern.

Thank You


Attachment: SyncfusionQuery_3ce4b0ee.rar

3 Replies

RS Renjith Singh Rajendran Syncfusion Team August 16, 2021 09:17 AM UTC

Hi Ssekamatte, 

Greetings from Syncfusion support. 

We could see that, you are adding a row with Null values into db when clicking on Add button using OnActionBegin event handler. So at these cases, by default the new row with Null values will be added to db immediately once Add button is clicked.  

Based on your scenario we suggest you not to add empty row into db when pressing Add button. Instead add row only when clicking Save, by checking the below highlighted condition in ActionBeginHandler as like below code, 

 
public async void ActionBeginHandler(ActionEventArgs<NationalizationPlan> args) 
{ 
    ... 
    else if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save && args.Action== "Add") 
    { 
        PreviousAction = Syncfusion.Blazor.Grids.Action.Add; 
        using (var db = new EWAPSContext()) 
        { 
            ... 
            Args.RowData.NationalizationPlanId = id; 
            db.NationalizationPlan.Add(Args.RowData); 
            db.SaveChanges(); 
        } 
        ... 
    } 
} 


Please get back to us if you need further assistance. 

Regards, 
Renjith R 



SJ Ssekamatte James August 26, 2021 07:47 AM UTC

Hello Syncfusion,

I am following up on this query I raised from last time.

Thank You



RS Renjith Singh Rajendran Syncfusion Team August 27, 2021 07:04 AM UTC

Hi Ssekamatte, 

Thanks for your update. Please get back to us if you need any further assistance on the suggested solution. 

Regards, 
Renjith R 


Loader.
Up arrow icon