blazor

How to add a Partial Class to a component in Blazor in Visual Studio 2019?

百般思念 提交于 2020-07-23 07:48:27
问题 I'm not finding where should I click to create a partial class in visual studio 2019. After I create a new "Razor Component" file, I can't add the partial class to it. Where do I add it? 回答1: Something like this? : - razor page with "code-behind" class 回答2: There are two ways to add code behind to Razor component: Add Base class and in component add @inherits this class, how is described in this answer. In this case base class shouldn't be partial. Since October 2019 we can use partial

How to add a Partial Class to a component in Blazor in Visual Studio 2019?

筅森魡賤 提交于 2020-07-23 07:46:21
问题 I'm not finding where should I click to create a partial class in visual studio 2019. After I create a new "Razor Component" file, I can't add the partial class to it. Where do I add it? 回答1: Something like this? : - razor page with "code-behind" class 回答2: There are two ways to add code behind to Razor component: Add Base class and in component add @inherits this class, how is described in this answer. In this case base class shouldn't be partial. Since October 2019 we can use partial

Random “Error: The circuit failed to initialize” with Blazor app

社会主义新天地 提交于 2020-07-22 12:00:52
问题 I am currently developing a Blazor server side app and I am experiencing a random error directly after starting the page. When I hit the F5-button or click any link on my index page, the page is reloaded and the error does not appear again. The error message is very generic and I really don't know where to start to debug this. The error occurs even when I entirely remove the content of my Index.razor page, which is the starting page. Any ideas how to approach this problem? I'm running this on

Random “Error: The circuit failed to initialize” with Blazor app

前提是你 提交于 2020-07-22 12:00:33
问题 I am currently developing a Blazor server side app and I am experiencing a random error directly after starting the page. When I hit the F5-button or click any link on my index page, the page is reloaded and the error does not appear again. The error message is very generic and I really don't know where to start to debug this. The error occurs even when I entirely remove the content of my Index.razor page, which is the starting page. Any ideas how to approach this problem? I'm running this on

Blazor HttpClient 3.2.0 Get call throwing exception because response header content-type not compatible with GetFromJsonAsync

和自甴很熟 提交于 2020-07-22 06:08:36
问题 I am calling a webapi from a blazor 3.2.0 client: protected override async Task OnParametersSetAsync() { if (SelectedComplexId != Guid.Empty) { residents = await HttpClient.GetFromJsonAsync<List<ResidentDTO>>($"api/complex/residents/{SelectedComplexId.ToString()}"); } } An exception is being thrown because the GetFromJsonAsync expects a content-type header of application/json in response. This is the api action method: [HttpGet("/residents/{complexId}")] public async Task<IActionResult>

Blazor client-side Application level exception handling

蓝咒 提交于 2020-07-20 10:52:09
问题 How to globally handle application level exceptions for client-side Blazor apps? 回答1: You can create a singleton service that handles the WriteLine event. This will be fired only on errors thanks to Console.SetError(this); public class ExceptionNotificationService : TextWriter { private TextWriter _decorated; public override Encoding Encoding => Encoding.UTF8; public event EventHandler<string> OnException; public ExceptionNotificationService() { _decorated = Console.Error; Console.SetError

Blazor TwoWay Binding on custom Component

馋奶兔 提交于 2020-07-15 12:15:28
问题 I'm creating a blazor server side app and have problems to bind a value between two custom components. I've looked through different example of how the bind or @bind is supposed to work but I cannot figure out what up to date information on this matter is. Given a model class User: public class User { [Mapping(ColumnName = "short_id")] public string ShortId { get; set; } public User() { } } I want to build a form which displays all properties of this user and has them in an input so it can be

Blazor TwoWay Binding on custom Component

寵の児 提交于 2020-07-15 12:12:42
问题 I'm creating a blazor server side app and have problems to bind a value between two custom components. I've looked through different example of how the bind or @bind is supposed to work but I cannot figure out what up to date information on this matter is. Given a model class User: public class User { [Mapping(ColumnName = "short_id")] public string ShortId { get; set; } public User() { } } I want to build a form which displays all properties of this user and has them in an input so it can be

Blazor preventDefault on submit form

我的未来我决定 提交于 2020-07-10 02:53:23
问题 Inside my EditForm , I want to prevent that the user submits the form by pressing the Enter key. I have tried the following, but didn't work. <button type="submit" @onkeypress:preventDefault>Save</button> Many thanks! 回答1: I have got this working by just putting 2 submit button's in the EditForm , with the first one disabled. <button type="submit" disabled style="display: none" aria-hidden="true"></button> <button type="submit">Save</button> 回答2: Here's a working code sample, run it and see

Blazor preventDefault on submit form

梦想的初衷 提交于 2020-07-10 02:53:18
问题 Inside my EditForm , I want to prevent that the user submits the form by pressing the Enter key. I have tried the following, but didn't work. <button type="submit" @onkeypress:preventDefault>Save</button> Many thanks! 回答1: I have got this working by just putting 2 submit button's in the EditForm , with the first one disabled. <button type="submit" disabled style="display: none" aria-hidden="true"></button> <button type="submit">Save</button> 回答2: Here's a working code sample, run it and see