C
C#2y ago
palapapa

❔ What is the difference between .cshtml files and .razor files?

I couldn't find a definitive answer about this anywhere. They both use the razor syntax. Are they interchangeable? Are there features that are only available in .cshtml files and not in .razor files and vice versa?
11 Replies
Thinker
Thinker2y ago
.cshtml is used for MVC apps while .razor is used for Blazor
palapapa
palapapaOP2y ago
So are they essentially the same? In the VS template for blazor apps it still mixes .cshtml and .razor files
Thinker
Thinker2y ago
They're not the same I think only the hosted Blazor template uses cshtml as well? razor is the main thing you work with in Blazor
palapapa
palapapaOP2y ago
So what's the difference? If they are using two different extensions then there must be some features that are only available in one of the two types of files right?
Thinker
Thinker2y ago
They're completely different frameworks Afaik MVC is server rendering while Blazor is either WASM based or streaming server rendering using SignalR
palapapa
palapapaOP2y ago
If they are different frameworks then why are they mixed in blazor apps?
Thinker
Thinker2y ago
because uhhh... I think that specific template hosts a Blazor app inside an MVC app for some reason?
palapapa
palapapaOP2y ago
But both of these file types use the same razor syntax? Are their contents the same, just that the extensions are different in different contexts?
Thinker
Thinker2y ago
They just look kind of similar afaik granted I'm not the most qualified person to talk about this
kocha
kocha2y ago
as far as i know are they the same syntax but compile to different things for example, a razor pages (.cshtml) generates the markup in an ExecuteAsync() method, while blazor (.razor) generates the markup into a BuildRenderTree() method
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?