如何返回包含 <li>
的字符串属性的模型元素并在 View 中显示它?
如果我只写 @Model.Messages 它会显示所有字符串..我需要 html 格式。
最佳答案
您可以使用带有 Content-Type text/html
的 Content
方法直接返回 HTML,而不需要 Html.Raw
.
public ActionResult MyHtmlView() {
return Content("<html><body>Ahoy.</body></html>", "text/html")
}
您可以传递任何您想要的 Content-Type,例如 text/xml
。
关于asp.net-mvc - 从 Controller 返回 html 字符串并显示在 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10661561/