Add RenderFragment-like functionality to pure partials and view components in pure Razor SST
See original GitHub issueIs 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:
- Created 2 years ago
- Reactions:5
- Comments:8 (7 by maintainers)
Top GitHub Comments
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.
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.