6

I'm following a tutorial trying to create a blazor project.

It says to add a razor page. When I right click on Pages folder ->Add->Razor Page, I get this prompt.

Prompt to create razor page

No matter what options I pick, the new file is a .cshtml file, not a .razor file.

I see other .razor files in the same folder by default.

Target Framework: .NET Core 3.1

Am I missing something?

vbp13
  • 1,040
  • 1
  • 10
  • 20

1 Answers1

8

I'm using Microsoft Visual Studio Professional 2019, Version 16.4.3.

Instead of creating a new "Blazor Page", go to the dialog to add a "New Item". From ASP.NET Core, Select "Blazor Component". This will create a new file called YourComponent.razor.

Bonus Fact: To create a code-behind file for the component, add a new class and specify the name YourComponent.razor.cs. Declare the class partial (because the .razor file itself makes a partial class declaration).

I am also new to Blazor and this has been a source of confusion for me. I hope that they make it more straight-forward in the next version of Visual Studio.

Vivian River
  • 31,198
  • 62
  • 198
  • 313