Is there any hot reload for blazor server-side?
Maybe you can try running your application from command prompt: dotnet watch run debug
Maybe you can try running your application from command prompt: dotnet watch run debug
@bind is essentially equivalent to the having both value and @onchange, e.g.: <input @bind=”CurrentValue” /> Is equivalent to: <input value=”@CurrentValue” @onchange=”@((ChangeEventArgs e) => CurrentValue = e.Value.ToString())” /> Since you’ve already defined @onchange, instead of also adding @bind, just add value to prevent the clash: <select value=”@SelectedCustID” @onchange=”@CustChanged” class=”form-control”> @foreach (KeyGuidPair i in CustList) { <option … Read more
When you read data from a data source such as an API, the data you receive is read only. Treat it as immutable, using record objects rather than class objects to represent the data. This is my demo record. It’s a simple record of the name and registration code for a country. All the properties … Read more
Note: The sample code below was created and tested in a WebAssembly Blazor App stand alone… An object reference is required for the nonstatic field, method, or property ‘member’ Let’s create the object class, whose object reference will be passed to your JavaScript’s object when initialized. When the user clicks on a location on the … Read more
As discussed in the comments, Blazor is an SPA so any loaded script is available on Blazor pages since it’s the same page. However, you don’t have to list them all in _Host.cshtml, and indeed you probably want to only load a specific script when it’s needed (e.g. not all users use a particular page/component … Read more
Create a shared service. Subscribe to the service’s RefreshRequested event in the parent and Invoke() from the child. In the parent method call StateHasChanged(); public interface IMyService { event Action RefreshRequested; void CallRequestRefresh(); } public class MyService: IMyService { public event Action RefreshRequested; public void CallRequestRefresh() { RefreshRequested?.Invoke(); } } //child component MyService.CallRequestRefresh(); //parent component … Read more
You may define a class service that implements the State pattern and the Notifier pattern to handle the state of your objects, pass state to objects, and notify subscriber objects of changes. Here’s a simplified example of such service, which enables a parent component to communicate with his children. NotifierService.cs public class NotifierService { private … Read more
There are three possibilities for getting the user in a component (a page is a component): Inject IHttpContextAccessor and from it access HttpContext and then User; need to register IHttpContextAccessor in Startup.ConfigureServices, normally using AddHttpContextAccessor. Edit: according to the Microsoft docs you must not do this for security reasons. Inject an AuthenticationStateProvider property, call GetAuthenticationStateAsync … Read more
Add the following to Blazor.Web.App.Startup.cs: services.AddHttpContextAccessor(); You also need this in <component-name>.cshtml @using Microsoft.AspNetCore.Http @inject IHttpContextAccessor httpContextAccessor Note: At the time when this answer was written, accessing the HttpContext was done as described above. Since then, Blazor has been under rapid development, and has fundamentally changed. It is definitely deprecated the usage described above, but … Read more
Quick answer Quoting Blazor docs: Component parameters Binding recognizes component parameters, where @bind-{property} can bind a property value across components. For your page: <EditForm Model=”model” OnValidSubmit=”Submit”> <MyInputComponent @bind-BindingValue=”model.Name” /> </EditForm> The child component MyInputComponent: <div> <InputText type=”text” @bind-Value=”@BindingValue” /> </div> @code { private string _value; [Parameter] public string BindingValue { get => _value; set { … Read more