How is the onclick event of HTML element handled in Blazor?
Blazor provides support for event handling of HTML element by referring a pointer to the function that is used to handle the event, For handling @onclick event of the HTML element, define a function/method in the @code section and then refer the delegate typed value to the @onclick attribute of the HTML element. Refer to the following code sample. Here, the ButtonClick is the event handler function (delegate typed value) assigned to @onclick of the button (HTML element).
How to implement State Management in Blazor?
State in Blazor: In Blazor, the user’s state is held in the server’s memory in a circuit. State Management refers to the persisting state of an application even after the connection is lost or disconnected. The state held for a user’s circuit may be any of the following, Need for State Management: In Blazor, the application is connected through a circuit to the server, which holds the user’s state and this can be lost or disconnected due to multiple reasons. Some of the reasons are as follows, Due to the above, user’s state may be lost and can also cause loss of crucial data gathered in the application such as, When data is lost after completing processes with multiple steps or creating a shopping list, it results in unnecessary time consumption. So, in Blazor, the data is stored in the local cache and state persists even when the circuit gets disconnected. Persisting the State/State Management: The three locations for persisting state in a Blazor application are as follows, Server-side (Database): To store data/state permanently or any data that spans multiple users or devices, the server-side database should be used. Client-side (Browser): Most suited when the user is actively creating transient data, that can be stored in the browsers, localStorage and sessionStorage. URL: This is best suited when the data/state needs to persist when navigating from one page of the application to another. For more information on state management, refer here. View Sample in GitHub
What is the use of UriHelper in Blazor?
The IUriHelper services are used for navigation and routing in Blazor. But IUriHelper service in Blazor has been replaced by NavigationManager from .NET Core 3.0 Preview 9. For more details refer to this link.
Does Blazor support lower versions of IE11?
No, Blazor WebAssembly (client-side Blazor) does not support any version of Internet Explorer due to the lack of WebAssembly support in IE. However, server-side Blazor can be made compatible with IE 11 by using additional polyfills to bridge the gaps in browser support.
How do I serialize and deserialize JSON in a Blazor application?
JSON (JavaScript Object Notation) is a lightweight data-interchange format and a text format that is language independent. In Blazor, the JsonSerializer class, found in the System.Text.Json namespace, assists with serializing and deserializing JSON data. [index.razor] In the provided sample, JsonSerialize.Serialize(object) is used to serialize the user object of the User class into a string. Then, JsonSerialize.Deserialize<ClassName>(JsonObject) is used to deserialize the serializedString string into a new instance of the User class named userCopy.