优秀的编程知识分享平台

网站首页 > 技术文章 正文

Blazor显示html内容的方法(br html)

nanyue 2024-09-14 06:19:13 技术文章 6 ℃

正常在razor文件中,如果这样写:

<div>
@content
</div>
@code
{
string content = "<h1>hello world</h1>";
}

你将得到的是:

但是你的本意是要让它正常的渲染html,要怎么来实现呢?

<div>
@((MarkupString)(@content)
</div>
@code
{
string content = "<h1>hello world</h1>";
}

@((MarkupString)(@content) 这样就告诉blazor,要用html格式进行渲染。

这样就正常了。


最近发表
标签列表