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

Blazor Question: Rendering (html file content containing javascript) dynamically #12615

Closed
Jeltz191 opened this issue Jul 26, 2019 · 1 comment
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@Jeltz191
Copy link

Jeltz191 commented Jul 26, 2019

Working from a Blazor server side project aspNetCore 3.0 latest preview
I just got started on this tech so please be gentle! The following works on an Index.cshtml page in the project:

@using Microsoft.AspNetCore.Html
@(new HtmlString("<h1>Hello World</h1>")  

Which renders a variable on the page as formatted html. included javascript also works fine in this html string (which is ultimately what my project needs to do - math equations with MathJAX work fine here).

But the exact same lines in an Index.razor page in the same project renders the text string rather than formatted html. But that is Ok, by moving to MarkupString in .razor page it works again:

@using Microsoft.AspNetCore.Components
@(new MarkupString("<h1>Hello World</h1>")  

But of course now an html string with javascript works but ignores javascript, Which I presume is related to the on-going divorce of Blazor/Razor from javascript and/or security concerns.

So a couple of quick questions about what Blazor will or won't do going into the future:

  1. Can I expect in the future HtmlString with javascript to stop working even though it currently works in the first .cshtml example above?
  2. What is/will be best practice for me to serve up dynamic legacy html files with embedded javascript? (in my case they are .htm files with MathJax javascript formatting of LaTex Math equations. And currently MathJax/javascript is the only non-browser specific way of displaying such equations given the failure to support html5 MathML directly. I do not really want to include them as static files in the Blazor project as they can be added to /modified going into the future.
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Jul 26, 2019
@Jeltz191
Copy link
Author

OK did not dig deep enough. case closed
Answer here : https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interop?view=aspnetcore-3.0

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

2 participants