-1

I got some businesslogic I want to handle inside of a .cs file. Depending on the outcome of that, I want to update the blazor UI, EG a toast notification or a variable change. How could I do that?

Thank you in advance.

0

2 Answers 2

1

This is not easy to answer as your question is not specific, and we don't know how proficient you are in programming. However, the following answer may illustrate the path you should take in the context of Blazor:

Your class should be defined as a service, which you should add to the DI container from the Startup class, and injected into your relevant components. This service class, generally speaking, should implement two patterns: The State pattern and the Notifier pattern. The service is supposed to hold some state, as for instance, a given value passed to the service from component A, which trigger an event handler that propagate this fact to other subscribing components, passing them the new value passed from component A via EventArgs or properties. The complicity of the service depends on the functionality you want to expose.

Search Google for strings like "enet stackoverflow Blazor notifier", and such like to see relevant code provided in my answers.

See these links: https://stackoverflow.com/a/62042629/6152891 https://stackoverflow.com/a/66370816/6152891

Sign up to request clarification or add additional context in comments.

Comments

0

You need to use ComponentBase.StateHasChanged in response to whatever is happening in your business logic. Since you didn't post any code it's hard to be more specific but that method will force the relevant component to re-render.

3 Comments

Thank you for anwsering. But before I make the call to rerender the component, how do I pass values from a class to a blazor component? Is that even possible? Or should all logic be handled inside the component itself?
You need to use Blazor Services. Business logic and data layer code live in Services, the UI in Components.
@Greenmercy oh I see, you're asking a much bigger question. Like React, Blazor doesn't have any built-in state management framework. There are numerous possible approaches. I like this one personally. github.com/klemmchr/MvvmBlazor

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.