Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

2.2K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda