C
C#13mo 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
Thinker13mo ago
.cshtml is used for MVC apps while .razor is used for Blazor
palapapa
palapapa13mo ago
So are they essentially the same? In the VS template for blazor apps it still mixes .cshtml and .razor files
Thinker
Thinker13mo 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
palapapa13mo 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
Thinker13mo ago
They're completely different frameworks Afaik MVC is server rendering while Blazor is either WASM based or streaming server rendering using SignalR
palapapa
palapapa13mo ago
If they are different frameworks then why are they mixed in blazor apps?
Thinker
Thinker13mo ago
because uhhh... I think that specific template hosts a Blazor app inside an MVC app for some reason?
palapapa
palapapa13mo 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
Thinker13mo ago
They just look kind of similar afaik granted I'm not the most qualified person to talk about this
chef drone builder
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
Accord13mo 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.