Replies: 2 comments
-
After digging through the ASP.NET Core sources I've found a solution. It's not the most elegant one and involves calling an internal method of an internal interface (IComponentRenderer.RenderComponentAsync). (answered my own question here) Would be good to either make IComponentRenderer.RenderComponentAsync public or provide a different solution that makes the described scenario possible without |
Beta Was this translation helpful? Give feedback.
0 replies
-
This also seems to be possible using the task {
let htmlHelper = container.GetService<IHtmlHelper>()
(htmlHelper :?> IViewContextAware).Contextualize(ViewContext(HttpContext = httpContext))
// RenderComponentAsync is an extension from "Microsoft.AspNetCore.Mvc.Rendering"
let! componentHtmlContent = htmlHelper.RenderComponentAsync<App>(RenderMode.ServerPrerendered)
let componentHtml: string =
using (new StringWriter()) (fun writer ->
componentHtmlContent.WriteTo (writer, HtmlEncoder.Default)
writer.Flush()
writer.ToString()
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context: Bootstrapping an F# app that uses server sider blazor/ razor components BUT does not use razor to define components. Instead I use FsBoleros DSL.
Everything works as expected but there is still on
.cshtml
file (_Host.cshtml
) that I'd like to replace with just (F#) code for a few reasons:All my code will be written in F# - but if I need to change things/ add code to the host razor file I need to mix in C#. While this works it's not optimal and I'd rather just have F# code and no special razor file.
F# Projects depend on file ordering. The razor file behaves a bit strange in that regard (I cant just reorder it like other files in my project using IDE tooling).
So the goal is to get rid of the
_Host.cshtml
file and replace it with just code.I've already invested 2 days in trying to do this. There seems to be little to no content on how to replace a razor page with just code or how to call a tag helper from non razor code. A little guidance on how to approach this would be highly appreciated, otherwise I'll burn more time on this.
My current understanding of what I have to do is:
Render a html response that includes
Is this correct ?
If so:
Generating the needed html page is trivial except for the prerendered annotated component. Is calling a tag helper the right approach to achieving that (as I'm having some issues with that) ?
Other Component rendering classes (and interfaces) are internal so I suspect that I should not use them. I also assume that I have to use the tag helper in order to get the html correctly annotated.
(This is the
_Host.cshtml
file to replace)(cross posted on stackoverflow)
Beta Was this translation helpful? Give feedback.
All reactions