Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
MichalSznajder opened this issue Feb 18, 2022 · 8 comments
Closed
1 task done
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-mvc-razor-views Features related to the Razor view engine for Razor pages and MVC views
Milestone

Comments

@MichalSznajder
Copy link

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 #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.

@javiercn javiercn added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-mvc-razor-views Features related to the Razor view engine for Razor pages and MVC views enhancement This issue represents an ask for new feature or an enhancement to an existing one labels Feb 18, 2022
@javiercn javiercn added this to the Backlog milestone Feb 18, 2022
@ghost
Copy link

ghost commented Feb 18, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@seangwright
Copy link
Contributor

seangwright commented Feb 20, 2022

I created this same feature request (referencing #4901) before the ASPNET Core 7 roadmap was defined
#37434

I do a lot of server-rendered HTML with ASPNET Core (and server-side rendering is popular again now!).
I'd love to see this feature to help improve the missing component model in SSR Razor.

@MichalSznajder
Copy link
Author

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.

@seangwright
Copy link
Contributor

MVC has never had a component model (like Web Forms or Blazor do), so HTML composition in the ways mentioned above has always been difficult/impossible 😖.

If static Blazor is meant to eventually replace classic MVC/Razor Pages style Razor rendering then we'd at least get a component model for our SSR HTML. Otherwise we need something like View Component slots to keep our Razor templates well factored and organized.

@danroth27
Copy link
Member

We think we will enable this with components as part of #6348

@seangwright
Copy link
Contributor

@danroth27 Does this mean developers that are building aspnetcore sites serving server-rendered HTML with View Components and Tag Helpers could weave them in with Razor Components for additional server-rendering flexibility?

Would this solution require any aspects of Blazor WASM or would enhanced Blazor server-side rendering be usable without the client-side aspect?

@danroth27
Copy link
Member

Does this mean developers that are building aspnetcore sites serving server-rendered HTML with View Components and Tag Helpers could weave them in with Razor Components for additional server-rendering flexibility?

Yup, that's the idea. Lots of details to work out though, so this could change.

Would this solution require any aspects of Blazor WASM or would enhanced Blazor server-side rendering be usable without the client-side aspect?

We already have a component tag helper that supports pure server-side rendering via RenderMode.Static, whichout involving Blazor Server or Blazor WebAssembly. The idea is to more deeply integrate using Blazor components for server-side rendering.

@seangwright
Copy link
Contributor

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.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-mvc-razor-views Features related to the Razor view engine for Razor pages and MVC views
Projects
None yet
Development

No branches or pull requests

4 participants