Using visual studio 2019 preview 2.0, .NET core SDK 3.0.100-preview8-013656. Server-side blazor application.
The blazor docs say the way to render a component is to call Html.RenderComponentAsync. I can't find this static Html class anywhere.
In the SDK directory, when I look inside Microsoft.AspNetCore.Components.dll, I see it has an HtmlRenderer class with such a method, but it's not static.
When I look at AspNetCore source, I see an HtmlHelperComponentExtensions class in namespace Microsoft.AspNetCore.Mvc.Rendering
MVC? I'm very confused. I'm using the latest SDK, is the doc simply old?
If I try to navigate directly to the route for my component, I just get (await Html.RenderComponentAsync()) written directly to my document along with signalR exceptions to the console.
When I look at AspNetCore source, I see an HtmlHelperComponentExtensions class in namespace Microsoft.AspNetCore.Mvc.Rendering
MVC? I'm very confused. I'm using the latest SDK, is the doc simply old?
No, the docs are not old... Html.RenderComponentAsync is not Blazor. Blazor does not have the concept of Html helpers, and its file extensions are either .razor, for Component files or .cs for normal class.
@(await Html.RenderComponentAsync<Counter>(new { IncrementAmount = 10 }))
The code above use the Html helper method RenderComponentAsync to render a component named Counter embedded in an MVC app, passing to its IncrementAmount property the value 10.
If you select server-side Blazor app, a file named _Host.cshtml is created for you in the Pages folder. This file contains the method RenderComponentAsync whose type specifier is App, which is the root element of the Blazor app, thus pre-rendering the whole app.
To do: Be sure to install the latest preview of Visual Studio 2019: .NET Core 3.0 Preview 8 requires Visual Studio 2019 16.3 Preview 2 or later
To install the latest Blazor WebAssembly template also run the following command: dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview8.19405.7
You should select Blazor Server App (server-side Blazor), and you'll get everything ready. You don't have to add anything else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With