Home > Blockchain >  Why can't I use partial view in a razor (blazor) component?
Why can't I use partial view in a razor (blazor) component?

Time:01-06

I have an existing ASP.NET MVC app with a lot of partial views and view components. It took me a while to realize you can't use @Html and @Component helpers inside a Razor (blazor) component, and since then I have been asking why? All they contain is static, common UI elements. This is a huge drawback. What is the best lightweight alternative to a partial view when using Blazor?

Do I have to make a Blazor component of every View Component and Partial View?

CodePudding user response:

In Blazor you have Razor Components, they can have a page directive so they are accessible directly from a route. A component can also contain other components which make Razor components really powerful. Simply put Razor component replaces both View Components and Partial Views in the Blazor world.

The big question is why would you want to?

As mentioned in the comment there are workarounds but it's really a hack rather than a nice solution in my eyes. But a simple solution if you need to do it while you migrate.

CodePudding user response:

Blazor apps are built using Razor components. A component is a self-contained portion of user interface (UI) with processing logic to enable dynamic behavior. Components can be nested, reused, shared among projects, and used in MVC and Razor Pages apps. This is like the partial view. For more information, see Nested components.

  •  Tags:  
  • Related