Unable to render script inside blazor component
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
I’m trying to embed github gist
in my .net 6 blazor wasm
application. <script>
tag in general is not allowed inside blazor component. so I added it as MarkupString
as shown below,
@(new MarkupString(@"<script src=""https://gist.github.com/fingers10/44eb8a5a5427b472d1c48ecb1b4268f7.js""></script>"))
But the rendered output is empty. When I inspected the html using browser, no such content is present in html.
Expected Behavior
Script should be added in html document and needs to be executed for github gist to be rendered.
Steps To Reproduce
- Create new blazor wasm project.
- Create a new component.
- Add the following
MarkupString
in the component html@(new MarkupString(@"<script src=""https://gist.github.com/fingers10/44eb8a5a5427b472d1c48ecb1b4268f7.js""></script>"))
- Run the application.
Exceptions (if any)
No response
.NET Version
6.0.101
Anything else?
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
.net - Blazor WASM Script tags should not be placed inside ...
Blazor WASM Script tags should not be placed inside components because they cannot be updated dynamically. Move the script tag to the index.html ......
Read more >ASP.NET Core Blazor JavaScript interoperability (JS interop)
This article explains general concepts on how to interact with JavaScript in Blazor apps. A Blazor app can invoke JavaScript (JS) functions ...
Read more >Adding script references in Blazor
Learn here about that how to add the script references manually in the Syncfusion Blazor Components.
Read more >JavaScript Errors - Telerik UI for Blazor
Troubleshooting JavaScript errors in the UI for Blazor suite. ... As a result, the script does not include all components, features or correct...
Read more >How to run code after Blazor component has rendered
This blog post will show you how to run code after your Blazor component has rendered, on every render or as needed. Sample...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@KristofferStrube I ended up improving your answer as component,
GithubGistSnippet.razor:
GithubGistSnippet.razor.cs:
githubgist.js:
Usage:
Output:
Hey @fingers10 if you need af workaorund for now then this works: