user1647160
user1647160

Reputation: 531

How to create .razor files

I've created a Blazor project using .net core 3.0 preview5 and VS2019 Enterprise. I want to create .razor files, but all of my options have .cshtml extensions.

When I'm creating my project, I'm using asp.net core 3.0 and Blazor server hosted options

Upvotes: 2

Views: 2504

Answers (4)

Alina
Alina

Reputation: 56

Right click on Pages-> Add->New Item...-> Razor Component

enter image description here

Upvotes: 0

TH Todorov
TH Todorov

Reputation: 1159

In VS 2019 16.3.0, adding "Razor Component" is what worked for me.

enter image description here

Upvotes: 4

Henk Holterman
Henk Holterman

Reputation: 273464

What works is:

Add, Add Class

and then change .cs to .razor before clicking [Add]

And immediately delete all the C# stuff of course.

Or you can copy/paste/rename any existing blazor component, like index.razor.

Upvotes: 2

App Pack
App Pack

Reputation: 1532

Make sure you've got the blazor extension installed. enter image description here

This should then allow you to click on the Pages Directory and at the top there's an Add Razor Page option. enter image description here

But I've got to admit, I tend to find it quicker to just select an existing page in the solution explorer and Ctrl-C Ctrl-V and rename it!

Note: At time of writing this is using the preview branch of Visual Studio 2019 and frameworks.

Upvotes: 1

Related Questions