简体   繁体   English

将HTML放在资源文件中的div中

[英]Placing HTML in div from resource files

I'm trying to place a HTML formatted text from my resources file to a <div> in my aspx page, but it places the text as is, not as HTML. 我正在尝试将HTML格式的文本从我的资源文件放置到我的aspx页面中的<div>上,但是它将文本原样而不是HTML放置。

myResources.resx: myResources.resx: 在此处输入图片说明

myPage.apsx: myPage.apsx:

<%@ Import Namespace="Resources" %>
....
....

<div>
    <%: myResources.myKey %>
</div>

This results in: 结果是:

This is the first line.<br>This is the second line.

When my wanted output is: 当我想要的输出是:

This is the first line.
This is the second line.

Actually <%: myResources.myKey %> encodes your string. 实际上<%: myResources.myKey %>您的字符串进行编码。 This is simple. 这很简单。 You can do the following: 您可以执行以下操作:

<div>
    <%= myResources.myKey %> 
</div>

<%= value %> will NOT encode the value. <%= value %>不会对值进行编码。

I would say that this should be avoided, but sometimes it is practically unavoidable. 我会说这应该避免,但有时实际上是不可避免的。

You can use the @Html.Raw method inside your view, eg @Html.Raw(STRING FROM RESX FILE HERE) 您可以在视图内部使用@ Html.Raw方法,例如@Html.Raw(STRING FROM RESX FILE HERE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM