question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add RenderFragment-like functionality to pure partials and view components in pure Razor SST

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Currently it is hard to easily pass HTML content into partial or custom component in Razor Pages or MVC scenarios. If you want to create a server side rendered component for box with header only way is to write custom tag helper.

Razor Components (available with Component Tag Helper with static rendering are not a solution since they don’t support HtmlHelper and Tag Helpes (so no linking via asp-page or no antiforgery protection in forms).

Describe the solution you’d like

Solution proposed in https://github.com/dotnet/aspnetcore/issues/4901 would be a good start. There is even example implementation in https://github.com/rdlaitila/AspNetCore.Mvc.ViewComponentSlots.

Additional context

Idea for this comes from Ruby on Rails where you can easily create HTML based components by using partial. See 3.4.2 Using Partials to Simplify Views section from Rails manual.

See also https://andrewlock.net/dont-replace-your-view-components-with-razor-components/ for some problems when tryign to convert from View Component into Razor Component.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
michalsznajdercommented, Feb 22, 2022

I am also on server side rendering only camp. By using Turbo from Rails 7 I can have pretty responsive app without all the burden of complicated JS frameworks or Blazor.

What I am missing is easy way to reuse render code in templates.

1reaction
seangwrightcommented, Oct 13, 2022

I’ve explored using the Blazor server-side HTML rendering and ran into all the caveats mentioned by Andrew Lock.

Blazor’s component model is 👍 so if it could play nice with the existing MVC Razor component pieces (view components/tag helpers), I’m eager to watch developments in that space.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Initialize a RenderFragment in a partial class in C# Blazor
I'm using a component from a third-party package, that accepts a RenderFragment as a parameter, and I want to assign a value to...
Read more >
How to Dynamically Build the UI in Blazor Components
You have two tools for generating your initial UI in a Blazor component: ASP.NET's Razor and Blazor's RenderFragment. Here's how to use both ......
Read more >
Building Components Manually via RenderTreeBuilder
In this post, I'm going to show you how you can build components manually using Blazors RenderTreeBuilder. Instead of using the traditional ...
Read more >
ASP.NET Core Razor components
Learn how to create and use Razor components in Blazor apps, including guidance on Razor syntax, component naming, namespaces, and component ...
Read more >
Partial Classes, RenderFragment and Lifecycle in Blazor ...
In this article, we are going to learn about using the partial classes and RenderFragment parameters to send the content to the Blazor ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found