How to use Html Helper methods in .razor file in Blazor

Viewed 1141

I recently started learning Blazor in .net core and I noticed I couldn't use the HTML Helper methods in the .razor file. Is there something I'm missing? I keep getting an error like "the name Html does not exist in the context".

What do I do?

1 Answers

You cannot use @helper directive anymore, you can create a Nested components Shared\Heading.razor and call it in the same razor component or other pages.

<h1 style="font-style:@headingFontStyle">Heading Example</h1>
<Heading />
@code {
    private string headingFontStyle = "italic";
}

or

@page "/heading-example"

<Heading />

See this document here for more details

Related