❔ Razor Component vs View Component vs Blazor
I do not want to use Blazor Client or Blazor Server. I just want to make view partials (Components) that I can pass parameters into to render my HTML.
Googling around is extremely confusing and I can't seem to get my project to recognize my Razor Components.
I started an ASP.NET Core Web App with Razor Pages. Let's say I just want to make a Heading component where I pass in a parameter
Title
equal to "Hello World". Right now, my HTML source is literally <heading></heading>
as opposed to e.g. <h1>Hello World</h1>
.
I've tried creating an _Imports.razor
file where I do @using Path.To.Components.Folder
amongst various other things and nothing seems to work. I feel like I'm finding conflicting information for Blazor vs Razor. Help?13 Replies
"Razor Pages" is MVC, not Blazor
so is "View Component"s what I should use?
MVC uses
.cshtml
files while Blazor uses .razor
filesOk. I think I'm understanding. Wow the naming of all this is seriously confusing
That's Microsoft for you
Last quick clarifying question here...
Looks like View Components are things where I'd want some sort of backend logic specific to that "partial"
but if i'm just rendering html with no backend tie ins, i should just use a partial?
The boilerplate and only being able to have one "parameter" (
model
) for a View Component kind of stinks compared to the Razor Component way of doing things, which sucks because I don't want to use Blazor and ship MB of JS/WASM nor do I want to do Blazor Server
you'd think they'd just support templating out of the box for Razor ComponentsWhat’s wrong with Blazor server?
I like to render .razor components in my .cshtml as html. Makes the swap fast for when the whole solution is blazor ready
Can you elaborate on this? I'd like to use Razor Components for templating without any Blazor features
Primarily latency and having to keep a consistent connection. And not that this is necessary but not wanting or needing the server to be in charge of simple javascript interactions that should be client side — so at this point there doesn't appear to be much benefit b/c writing an API endpoint is roughly the same amount of work I'd be doing with writing a Blazor service/"endpoint" anyway
I have a couple of razor pages for routing. Inside them i use the .razor for content. Can show example later
example
Cool thank you. I'll look more into this
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.