使用 MVC 3 (ASPX ViewModel) 显示数据库中的 HTML

发布于 2024-09-30 08:45:13 字数 199 浏览 0 评论 0原文

我在存储和显示 SQL 数据库中的数据时使用 MVC 3(ASPX ViewModel)。我尝试使用原始输入来存储它以及使用 HttpUtility.HtmlEncode。当我尝试显示时,两者都不起作用。我尝试过使用 HttpUtility.HtmlDecode 以及使用 <%: Model.MyHtmlVariable %>。我错过了什么吗?

I'm using MVC 3 (the ASPX ViewModel) while I store and display data from my SQL database. I've tried using the raw input to store it as well as using HttpUtility.HtmlEncode. Neither are working when I try to display. I've tried using the HttpUtility.HtmlDecode as well as using <%: Model.MyHtmlVariable %>. Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仲春光 2024-10-07 08:45:13

使用传统的“<%= html %>”语法应该为您呈现它,但可能不取决于您正在做什么。如果没有,请尝试将其包装在 HtmlString 对象中,如下所示:

<%= new HtmlString(html) %>

MVC 应该尊重这一点并正确地呈现它。

如果您只是想显示编码后的 HTML,则“<%: html %>”语法是你的朋友

Using the traditional "<%= html %>" syntax should render it out for you but may not depending on what you're doing. If not, try to wrap it in an HtmlString object, like so:

<%= new HtmlString(html) %>

MVC should respect that and render it out properly.

If you're just looking to display the encoded HTML, the "<%: html %>" syntax is your friend

記柔刀 2024-10-07 08:45:13

您需要创建一个 div 来定位并使用对控制器操作的 jquery/javascript 调用来设置 html。

jQuery.get("/Controller/Action", 
     function(response) {  
          $("#MyDiv").html(response) 
     });  

看看类似的东西是否有效。

You need to create a div to target and set the html using an jquery/javascript call to the controller action.

jQuery.get("/Controller/Action", 
     function(response) {  
          $("#MyDiv").html(response) 
     });  

See if something like that works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文