asp.net-mvc - 从 Controller 返回 html 字符串并显示在 View 中

标签 asp.net-mvc asp.net-mvc-3

如何返回包含 <li> 的字符串属性的模型元素并在 View 中显示它? 如果我只写 @Model.Messages 它会显示所有字符串..我需要 html 格式。

最佳答案

您可以使用带有 Content-Type text/htmlContent 方法直接返回 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/

相关文章:

asp.net-mvc - 如何在 mvc4 的特定 View 中添加单个 css 文件?

javascript - MVC 中的 Kendo UI 网格页面大小

c# - mvc 对数字的默认验证

c# - MVC3 - 引用哪个模块中的单独服务项目?

asp.net - 应用 META 标签后,IE 仍会缓存页面内容几秒钟。该怎么办?

c# - 在 ActionFilterAttribute 中设置 TempData

asp.net-mvc - ASP.NET MVC 3 多个模型到单个表单

c# - MVC3 View 中的条件逻辑是一种好的做法吗?

asp.net-mvc-3 - 在 MVC3 中呈现 RDL(报告服务)

asp.net-mvc - Razor 编码一切