ASP.net HTMLDecode 不适用于资源条目

发布于 2024-12-23 15:44:12 字数 441 浏览 5 评论 0原文

我有一个 ASP.net MVC 项目,它在整个项目中使用资源条目 (.resx)。

很少有资源提供 HTML,其中

example: Hello <b>World!</b>

包含段落 href 等。由于资源存储在 XML 中,因此条目是 HTMLEncoded 的

,即上面的示例如下所示。

eg: Hello &lt;b&gt;World!&lt;/b&gt;

因此,无论在哪里显示资源,都不会呈现 HTML 格式,而是将 HTML 显示为可见文本。

我尝试使用 HttpUtility.HTMLDecode 和 Server.HTMLDecode,但两者都不起作用。

怎么了?还有其他解决资源问题的方法吗?

I have a ASP.net MVC project, which utilizes resource entries (.resx) through out the project.

Few the resources fed, have HTML in it

example: Hello <b>World!</b>

With paragraphs href and more. As the resources are stored in an XML, the entries are HTMLEncoded

i.e the above example looks like this

eg: Hello <b>World!</b>

Due to this, wherever the resources are displayed, the HTML formatting does not render, and instead the HTML is displayed as visible text.

I tried to use HttpUtility.HTMLDecode and Server.HTMLDecode, but both wont work.

What is wrong? Any other work around resources?

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

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

发布评论

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

评论(1

折戟 2024-12-30 15:44:12

以下两种方法对我来说都很好:

    <%= Resource.MyResource %><br />
    <asp:Label runat="server" Text="<%$ Resources:Resource, MyResource %>" /><br />

浏览器以粗体显示诸如 Text 之类的资源条目。

某些控件对其输入进行自动 HTML 编码。这可能就是你身上发生的事情吗?

Both of the following work fine for me:

    <%= Resource.MyResource %><br />
    <asp:Label runat="server" Text="<%$ Resources:Resource, MyResource %>" /><br />

A Resource entry such as <b>Text</b> is displayed in bold by the browser.

Some Controls do automatic HTML encoding of their inputs. Could that be what's happening for you?

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