Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

await InvokeAsync(StateHasChanged) does not change the database content unless page is reloded

$
0
0

I'm doing very basic CRUD Blazor Web App, my Create and Delete works just fine, as soon as I add or remove an item in my database the item is immediately updated on my razor page. But not when I use the update method, I tried different approaches and nothing works. I don't really understand why create and delete works just fine, but not update?

I'm calling methods with onclick - buttons. When user click "Update"/"Create"/"Delete" a form will show that ask about Id of the record you want to delete or update. Or just ask to fill in to create a new data.

Here is my "Create" method that works as it should, as soon as the user press the Add button the list with data from my database shows.

private async Task AddTrick(){await dr.Create(newTrick);isVisibleCreate = false;newTrick = new Tricks();}

Here is my Update method from my razor page:

private async Task LoadTrick(){   trick = await dr.GetTrickByIdAsync(idTrick);}private async Task UpdateTrick(){   await dr.Update(trick);   isVisibleUpdate = false;   trick = await dr.GetTrickByIdAsync(idTrick);   await InvokeAsync(StateHasChanged);}

Here are my CRUD methods from another class

public async Task Create(Tricks trick){_context.Trick.AddAsync(trick);await _context.SaveChangesAsync();}public async Task Update(Tricks trick){var t = await _context.Trick.FindAsync(trick.Id);t.Description = trick.Description;t.Name = trick.Name;t.Length = trick.Length;t.Done = trick.Done;await _context.SaveChangesAsync();}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>