6
votes

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?

1
you should be adding a razor component, Pages folder ->Add->New item then pick razor component which has a purple icon on it. - David Masterson
That worked. Thanks. - vbp13

1 Answers

6
votes

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.