在 MVC 中将 HTML 字符串显示为呈现的页面

Show HTML string as rendered page in MVC

在 MVC4 应用程序中,我有一个 HTML 字符串,我在其中呈现 Textarea 中的字符串,它显示为简单字符串。

在 MVC 中有没有办法通过 iframe 或其他方式将 HTML 字符串呈现为实际页面?

希望回答对您有所帮助

您可以传递HTML字符串以通过模型查看。它将在 textarea

中显示 HTML 字符串

控制器

public ActionResult HTMLView()
{
    string result= "<HTML><BODY><DIV>Testing</DIV></BODY></HTML>";
    return View((object)result);
}

查看

@model string
    <div>
        @Html.TextArea("html", @Model, new { id="htmlTextArea" })
    </div>