How to set the focus to an InputText element?

In .NET5 it will be much simpler: <button @onclick=”() => textInput.FocusAsync()”>Set focus</button> <input @ref=”textInput”/> @code { ElementReference textInput; } NOTE: this feature was introduced in .NET5 Preview 8 so might change until the final release! Also worth mentioning that in .NET5 RC1 JavaScript isolation was introduced via JS Module export/import. So if you still need … Read more

How to use bind-value and bind-value:event on a custom component Blazor

Yes Blazor supports 2 way binding. It works with EventCallbacks (which must be triggered) and default uses name convention based Events e.g.: {PropertyName}Changed. Also you can override this naming convention @bind-{Prop}:event=”{EventCallbackName}”. In your code example you are just overriding this default Event name, never triggering it. In your code you have 2 issues: You MUST … Read more

onChange event not firing Blazor InputSelect

Note: InputSelect is a component element, not HTML element, which is why you cannot apply to it the @onchange compiler directive. This directive is applied to elements, usually but not necessarily with the value attribute to form the so- called two way data-binding. @bind-Value is a compiler directive directive instructing the compiler to produce code … Read more

Require authorization on ALL Blazor pages

I believe that will work… Place the following code snippet in the _Imports.razor file @using Microsoft.AspNetCore.Authorization @attribute [Authorize] In that case, when the Index page is hit, the user will be redirected to the Login page. If you want to perform authentication before the Blazor App is being render, add the code snippet from above … Read more

What’s the difference between RenderMode.Server and RenderMode.ServerPrerendered in blazor?

Explained at ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 9: Static Statically render the component with the specified parameters. Server Render a marker where the component should be rendered interactively by the Blazor Server app. ServerPrerendered Statically prerender the component along with a marker to indicate the component should later be rendered … Read more

How to fix ‘The current thread is not associated with the renderer’s synchronization context’?

I have just implemented a State Container like this and ran into the same error – but my service needs to be a singleton. So I found an example on the aspnetcore git that does exactly what the error message says to do. Call InvokeAsync — not from your state container but when you try … Read more

Blazor – cannot convert from ‘method group’ to ‘EventCallback’

You were close: <ChildComponent Item=”someModel” T=”SomeModel” DeleteCallback=”OnDeleteSomeModel” /> @code { SomeModel someModel = new SomeModel(); void OnDeleteSomeModel(SomeModel someModel) { … } } The EventCallback uses a generic type and blazor cannot infer it if you don’t pass the type to the component. This means that if you have a EventCallback<T> you need to pass the … Read more

tech