首页 > 解决方案 > 仅在 .cshtml 页面(剃刀)中呈现 html 标记(链接)

问题描述

例子:

string ChatMessage = "Check this website <a href=\"http://www.example.com\">http://www.example.com</a><script>alert(1);</script><h1>Hi</h1>";

@Html.Raw(ChatMessage)

输出

Check this website http://www.example.comHi";

我想

Check this website http://www.example.com<script>alert(1);</script><h1>Hi</h1>";

我可以使用@Html.Raw(它对 JavaScript 注入和其他 html 标签开放)。

如何使用 @Html.Raw 或其他东西仅<a href="http://www.example.com">http://www.example.com</a>在 .cshtml 页面中呈现?

标签: c#asp.netasp.net-corerazorrazor-pages

解决方案


推荐阅读