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.
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?
You can add support for Pages to any ASP.NET Core MVC app by simply adding a Pages folder and adding Razor Pages files to this folder. Razor Pages use the folder structure as a convention for routing requests.
Razor is a templating engine that combines C# with HTML to build dynamic web content. Blazor is a component-based, single-page app framework for building client-side web apps using . NET that works well with all modern browsers via WebAssembly for client-side Blazor.
Select “ASP.NET Core” from the left panel, then select “Razor Page” from the templates panel and name it “EmployeeData.cshtml”. Click “Add”. This will add an “EmployeeData.cshtml” page to our “BlazorSPA.Client/Pages” folder.
We start with an existing Razor Pages application which has been converted to .NET Core 3: First, you have to add Blazor support into your application. This support will allow you to render Blazor components from a Razor page. The official documentation goes through the process but here’s a quick rundown of it.
Most files in Blazor projects are.razor files. Razor is a templating language based on HTML and C# that is used to dynamically generate web UI. The.razor files define components that make up the UI of the app. For the most part, the components are identical for both the Blazor Server and Blazor WebAssembly apps.
Right-click Counter.razor and delete it. Right-click the Pages folder. Select Add -> Razor Page and create a new page named Counter.razor. If you receive a “scaffolding” error, you can instead select another file format and give it a .razor file extension. A Razor page is a self-contained view.
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.
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