blazor

Detect client closing connection Blazor

假如想象 提交于 2020-06-16 17:06:52
问题 I have a loop that I have got running the whole time the client is on the page but I got no way to close the loop so that always remains running even when the user already disconnected. Is there a lifecycle method that runs when the user closes the connection? or is there a different way? 回答1: I'm not sure just implementing the IDisposable Interface can help you here, but implementing the Blazor Server circuit handler may. I vaguely recall that a similar question to yours was asked in

How to replace Blazor default “soft 404” with an actual 404 status code response

陌路散爱 提交于 2020-06-16 03:53:10
问题 The default Blazor approach to 404 is to create a soft 404 in App.razor, but I would like to adhere to search engine best practices to actually return the 404 status code while displaying a 404 page on Azure. I tried to remove the element in App.razor to see if I could force a 404, however, that did not compile. Any suggestions? 回答1: I was able to return 404 http status codes when using server side prerendering in the Blazor WebAssembly App (ASP.Net Core Hosted) Template When I pointed the

Blazor - Compare Previous and Next State

て烟熏妆下的殇ゞ 提交于 2020-06-15 07:10:16
问题 I have a table of students in Blazor, which is coming from an api, and I am also receiving a pushed data to update the students info which is basically the score upon a change in the database, the push is working fine and the score is being updated but I also want to change the background colour of the field that has been updated in the table upon a change in the score to red just the td tag for few sec, my code is as follow: @foreach(var student in SS.GetStudents()){ <tr> <td> student.name <

Blazor - Compare Previous and Next State

自作多情 提交于 2020-06-15 07:10:08
问题 I have a table of students in Blazor, which is coming from an api, and I am also receiving a pushed data to update the students info which is basically the score upon a change in the database, the push is working fine and the score is being updated but I also want to change the background colour of the field that has been updated in the table upon a change in the score to red just the td tag for few sec, my code is as follow: @foreach(var student in SS.GetStudents()){ <tr> <td> student.name <

How to create “Code Behind” Blazor Components with VS 2019?

自作多情 提交于 2020-06-15 07:06:09
问题 I can create an inline component like <h1>@foo</h1> @functions { string foo = "foo"; } However when I create Foo.razor containing just: <h1>@foo</h1> And Foo.razor.cs containing: namespace MyApp.Client.Components { public class Foo: ComponentBase { public string foo; } } I get: Error CS0101 The namespace 'MyApp.Client.Components' already contains a definition for 'Foo' I am using the latest VS 2019 and Blazor libraries. What am I doing wrong? 回答1: Currently, the "code-behind" and .razor view

Difference between @bind and @bind-value

风格不统一 提交于 2020-06-14 06:31:26
问题 What is the difference of using @bind and @bind-value ? I made this simple example, and testing it in the browser, I didn't see any difference. <p>@@bind @increment1</p> <input type="text" @bind="@increment1" /> <p>@@bind-value @increment2</p> <input type="text" @bind-value="@increment2" /> @code { string increment1; string increment2; } 回答1: Quoting Component Binding docs: Data binding to both components and DOM elements is accomplished with the @bind attribute. (...) Using @bind with a

Difference between @bind and @bind-value

强颜欢笑 提交于 2020-06-14 06:31:08
问题 What is the difference of using @bind and @bind-value ? I made this simple example, and testing it in the browser, I didn't see any difference. <p>@@bind @increment1</p> <input type="text" @bind="@increment1" /> <p>@@bind-value @increment2</p> <input type="text" @bind-value="@increment2" /> @code { string increment1; string increment2; } 回答1: Quoting Component Binding docs: Data binding to both components and DOM elements is accomplished with the @bind attribute. (...) Using @bind with a

How can I host ASP.NET API and Blazor Web Assembly like an JavaScript-SPA?

余生长醉 提交于 2020-06-11 07:55:08
问题 Context: We want to create a Single Page Application that runs with Blazor WebAssembly on the client-side. On the server-side, the solution has an ASP.NET MVC which includes some ApiController classes for our REST APIs. We want to use ASP.NET API on the server-side instead of Blazor Server because we want to provide a REST interface with ApiController classes for unknown consumers. Here is my client-side (Blazor WebAssembly) and server-side (ASP.NET API) project in a single solution: A first

Blazor HttpClient stuck in GetAsync

十年热恋 提交于 2020-06-11 06:10:29
问题 I'm making test in a Client Side Blazor app targeting Blazor 3.0.0-preview4-19216-03 The razor page: @page "/counter" @using BlazorServiceTest @inject IWebCrawlServiceAsync WebCrawler <h1>Counter</h1> <p>Current count: @debug</p> <button class="btn btn-primary" onclick="@IncrementCount">Click me</button> @functions { string debug = ""; async void IncrementCount() { debug = await WebCrawler.GetWeb(); } } The dependency injection: using BlazorServiceTest; using Microsoft.AspNetCore.Components

Can you use IAsyncEnumerable in Razor pages to progressively display markup?

六月ゝ 毕业季﹏ 提交于 2020-06-10 16:54:50
问题 I've been playing around with Blazor and the IAsyncEnumerable feature in C# 8.0. Is it possible to use IAsyncEnumerable and await within Razor Pages to progressively display markup with data? Example service: private static readonly string[] games = new[] { "Call of Duty", "Legend of Zelda", "Super Mario 64" }; public async IAsyncEnumerable<string> GetGames() { foreach (var game in games) { await Task.Delay(1000); yield return game; } } Example in razor page: @await foreach(var game in