Search code examples
asp.net.netasp.net-mvcresxhtml-encode

ASP.net HTMLDecode not working for Resource entries


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 &lt;b&gt;World!&lt;/b&gt;

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?


Solution

  • 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?