blazor-server-side

blazor variable argument passing to onclick function

我的梦境 提交于 2020-02-25 21:26:29
问题 I want to pass the int i into the button onclick function for each list item. I expected the "clickItem" function will receive 0..2 for correspondig list item. But it come out that it always receive 3 as argument. It seems that the variable i in the clickItem(i) is not evaluated at the time of render of the for loop. I have tried changing it to "clickItem(@i)" but it is still the same. What should I do? (I am using blazor server side, .net core 3 preview 5) @for (int i = 0; i < 3; i++) { <li>

.Net Core Blazor - Javascript error using input checkbox binding with <tr> onclick

房东的猫 提交于 2020-02-25 07:05:52
问题 I am writing a Blazor component for a Blazor server side app, that will display a table of data and allow one or more rows to be selected. The idea is that there will be a checkbox in the first column of the table and the row data in the remaining columns. The row is selected/deselected by clicking the checkbox OR by clicking anywhere in the row. This is done by binding an input checkbox to a bool on the row object and by using onclick on the tr element. <tr @onclick="() => item.Toggle()">

Is it safe to call StateHasChanged() from an arbitrary thread?

别说谁变了你拦得住时间么 提交于 2020-02-20 07:12:48
问题 Is it safe to call StateHasChanged() from an arbitrary thread? Let me give you some context. Imagine a Server-side Blazor/Razor Components application where you have: A singleton service NewsProvider that raises BreakingNews events from an arbitrary thread. A component News.cshtml that gets the service injected and subscribes to BreakingNews event. When the event is raised, the component updates the model and calls StateHashChanged() NewsProvider.cs using System; using System.Threading;

Blazor component : refresh parent when model is updated from child component

天大地大妈咪最大 提交于 2020-02-05 04:28:04
问题 I'm using Server-side Blazor components in ASP.NET Core 3 preview 4. I have a parent component, and child components, using the same shared model, like this : Model : public class CountModel { public int Count { get; set; } public void Increment() { Count++; } } Parent component : @page "/count" <CascadingValue Value="currentCount"> <h1>Count parent</h1> <p>Current count is : @currentCount.Count</p> <button class="btn btn-primary" onclick="@currentCount.Increment">+1 from parent</button>

How to obtain the target element on click event in Blazor

烈酒焚心 提交于 2020-02-03 11:02:09
问题 I want the exact target on which the click event has been triggered in ASP.NET Core blazor. Is this achievable? 回答1: You can use @ref to get a reference to a DOM object, then pass it as a parameter to your handler function. You can then pass it as a parameter to the JS Interop. For example: Counter.razor @page "/counter" @using Microsoft.JSInterop @inject IJSRuntime JSRuntime <h1>Counter</h1> <p>Current count: @currentCount</p> <p>Last button clicked: @lastButtonClicked</p> <button @ref

Launch Google Maps On Blazor

不问归期 提交于 2020-02-02 05:48:07
问题 I am trying to launch Google maps on my Server side Blazor app using JSInterop. I seem to have tried just about everything but can't get the map to show. Unfortunately there is very little samples if any about it on the internet since it's a fairly new framework and I am equally just getting my feet wet on Blazor myself, so I am probably doing a whole lot of things wrong. Any nudge in the right direction would be appreciated. In my component file, I have: @page "/MapTest" @inject IJSRuntime

Blazor Grid Bound Column by Field Name

核能气质少年 提交于 2020-01-24 18:23:06
问题 I'm studying some paid grid components and they have a pretty cool "Bound Column" technique: <TelerikGrid Data=@GridData> <GridColumns> <GridColumn Field="TemperatureC" Title="Temp. C" /> <GridColumn Field="Summary" /> </GridColumns> <GridToolBar> <GridCommandButton Command="Add" Icon="add">Add Forecast</GridCommandButton> </GridToolBar> </TelerikGrid> <DxDataGrid Data="@DataSource"> <DxDataGridColumn Field="@nameof(ProductFlat.Id)"> </DxDataGridColumn> <DxDataGridColumn Field="@nameof

Is there any hot reload for blazor server-side?

ⅰ亾dé卋堺 提交于 2020-01-22 16:00:28
问题 I have just one, quick question. Is there way to hot reload a blazor app? At least, .razor files? Now I'm hosting my app on local IIS (not IIS express). I was looking through internet, but i didn't found anything helpful. Thank you all for anwsering :) 回答1: Maybe you can try running your application from command prompt: dotnet watch run debug 来源: https://stackoverflow.com/questions/58172922/is-there-any-hot-reload-for-blazor-server-side

How to update server-side changes on the client side for Blazor Server app?

瘦欲@ 提交于 2020-01-13 07:14:07
问题 My ChangeValues server-side event occurs every 5 seconds but on client-side, I only see the first value of the number variable. See code below @page "/" <button class="btn btn-primary" @onclick="ChangeValues">Click me</button> <b>@number</b> @code { double number; private Random rnd = new Random(); private System.Threading.Timer _timer; void ChangeValues() { number = rnd.NextDouble(); Console.WriteLine(number); } private void DoWork(object state) { ChangeValues(); } protected override async

How to update server-side changes on the client side for Blazor Server app?

痞子三分冷 提交于 2020-01-13 07:13:03
问题 My ChangeValues server-side event occurs every 5 seconds but on client-side, I only see the first value of the number variable. See code below @page "/" <button class="btn btn-primary" @onclick="ChangeValues">Click me</button> <b>@number</b> @code { double number; private Random rnd = new Random(); private System.Threading.Timer _timer; void ChangeValues() { number = rnd.NextDouble(); Console.WriteLine(number); } private void DoWork(object state) { ChangeValues(); } protected override async