Change variable value on input key press on Blazor

Answer: Quoting Data Binding docs: <input @bind=”CurrentValue” @bind:event=”oninput” /> Unlike onchange, which fires when the element loses focus, oninput fires when the value of the text box changes. Using @oninput: You can achieve it without @bind directive: <input value=”@CurrentValue” @oninput=”(e)=> CurrentValue = e.Value.ToString()”/> InputText & oninput To people that are looking for oninput with InputText … Read more

How to acess the appsettings in blazor webassembly

Using ASP.NET Core 6.0 Blazor configuration. Blazor WebAssembly loads configuration from the following app settings files by default: wwwroot/appsettings.json. wwwroot/appsettings.{ENVIRONMENT}.json, where the {ENVIRONMENT} placeholder is the app’s runtime environment. Example: wwwroot/appsettings.json { “h1FontSize”: “50px” } Pages/ConfigurationExample.razor @page “/configuration-example” @using Microsoft.Extensions.Configuration @inject IConfiguration Configuration <h1 style=”font-size:@Configuration[“h1FontSize”]”> Configuration example </h1> Warning Configuration and settings files in a … 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

Blazor the type or namespace name ‘App’ could not be found (are you missing a using directive or an assembly reference?)

To use Blazor you need to have VS2019 preview edition or enable preview features on VS2019 by checking Tools -> Options -> Environment -> Preview Features -> Use previews of the .NET Core SDK or on the older versions of VS2019 Tools -> Options -> Projects and Solutions -> .NET Core -> Use previews of … Read more

Blazor template with menu across the top

The sidebar in Blazor isn’t something special. If you check MainLayout.razor you’ll see a reference to a NavMenu component with the sidebar class : <div class=”sidebar”> <NavMenu /> </div> If you open NavMenu.razor you’ll see it’s just a Bootstrap Navbar, conveniently packed in a reusable component. Update Blazor uses Bootstrap which makes the rest of … Read more

How to show/hide an element in real time (Blazor)?

The hidden html attribute also works to hide an element. <p hidden>This paragraph should be hidden.</p> To bind to Model: <p hidden=”@HideLabel”>I am Hidden When HideLabel == true</p> <p hidden=”@(!HideLabel)”>I am Hidden when Hidelabel == false</p> <button @onclick=”@Toggle”>Show/Hide</button> @code { private bool HideLabel { get; set; } = false; private void Toggle() { HideLabel = … Read more

Disable layout for page under Blazor

In my Blazor-server-side project, i resolved this issue with following two steps. Step 1: First create a new empty razor component named EmptyLayout. EmptyLayout.razor @inherits LayoutComponentBase <div class=”main”> <div class=”content px-4″> @Body </div> </div> Step 2, To set Layout=null, I use the below code in the top of all required pages @layout EmptyLayout

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