//Html.Raw其实是调用 new Microsoft.AspNetCore.Html.HtmlString(xxx) @{ ViewData["Title"] = "Home Page"; } <div class="text-center"> @(new Microsoft.AspNetCore.Html.HtmlString("<b>Hello World!</b>")) @(new Microsoft.AspNetCore.Html.HtmlString("<script>alert('Hello World1!')</script>")) @{ string message = "<strong><font color='red'>This is bold!</font></strong>"; message = "<script>alert('Hello World2!')</script>"; } <p><span>@Html.Raw(message)</span></p> @*生成红色加粗字体This is bold!*@ <p><span>@message</span></p> @*展示message这个字符串的所有内容*@ </div>