dotnet / dotnet/dotnet-api-docs

HtmlString doesn't work in Blazor applications, and documentation is not clear about this

Open
#7,225 2 comments 0 reactions 0 assignees View on GitHub
area-System.Web Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

When trying to render raw html into a razor page, most people just use HtmlString type to convert a string into full html. When I wanted to do this in my Blazor app, I was able to reference HtmlString but it wasn't working as expected at runtime. After pinging some devs in the ASP.NET team, I was told that this is by design as Blazor requires MarkupString to be used instead. We should either:
- Add more documentation onto HtmlString to indicate that it shouldn't be used in Blazor
- Add a code analyzer which detects uses of HtmlString inside a Blazor app and emit a warning and suggestion to use MarkupString instead

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.