Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

2.2K
Visualizações
What is the difference between "razor" and "cshtml" files?

What is the difference between "razor" and "cshtml" files in ASP.NET. Should we use ".razor" file in "razor-components" application instead of ".cshtml"?

over 4 years ago · Santiago Trujillo
7 Respostas
Responde à pergunta

0

It depends on which ASP.NET you mean...

For example, in terms of Blazor:

As of .NET Core 3.0 Preview 4 SDK (3.0.100-preview4-011223) it is noted:

  • Rename all _ViewImports.cshtml files to _Imports.razor.
  • Rename all remaining .cshtml files to .razor.

So if you are building a Blazor Web App using .NET Core 3.0 Preview 4 and later, you should be using .razor instead of .cshtml.

Source: https://devblogs.microsoft.com/aspnet/blazor-now-in-official-preview/

over 4 years ago · Santiago Trujillo Relatório

0

Razor is a markup syntax that lets you embed server-based code into web pages using C# and cshtml is the extension of razor file Cshtml = cs (C#) + HTML

Components are typically implemented in Razor Component files (.razor) using a combination of C# and HTML markup (.cshtml files are used in Blazor apps).

.cshtml and .razor is the same thing we use .cshtml file in blazor app and .razor in razor components

over 4 years ago · Santiago Trujillo Relatório

0

razor helps you embed serverside code like C# code into web pages. cshtml is just a file extension. razor view engine is used to convert razor pages(.cshtml) to html.

over 4 years ago · Santiago Trujillo Relatório

0

.cshtml files are razorpages or MVC views, they does not contain any C#-written client-side code. If you wan to do so, you must use JavaScript. However, a .razor file, also know as a Razor component, can have C# written in it and run on client's browser.

over 4 years ago · Santiago Trujillo Relatório

0

Used in your standard .cshtml files, and implemented like so:

<BlazorSample.Components.MyComponent />

These new extensions are used for Razor Components.

https://docs.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-3.1

over 4 years ago · Santiago Trujillo Relatório

0

I might be wrong but .cshtml file created when adding a new Razor page is a new html page, and .razor file created when adding a new Razor component is a component that will fit into a Razor page.

over 4 years ago · Santiago Trujillo Relatório

0

Since Blazor can execute C# on Client side, now there are 2 places - client and server - where Razor code can be executed. So client side has extension ".razor" and server side - ".cshtml"

I created a new WebAssemblyHosted application and found that:

  • There are 3 projects created in solution: Client, Server, and Shared
  • Client project has .razor files and does not have .cshtml files. This project will be compiled and sent .dll to client side, and then executed by .Net which is integrated in browser
  • Server project has .cshtml files and does not have .razor files. This code compiled and executed on server, as it was done in old asp
  • Shared project contains common types/classes for both Client and Server. Now (finally) you do not need to declare the model class twice in C# on server and in JS on client as it was before. And of cause you do not need map one to the other.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda