use*_*624 2 asp.net-mvc razor asp.net-mvc-4
我有一个这样的公共课程:
namespace MyProgram.Common
{
public static class UIStrings
{
public const string Title = "Hellow World"
public const string SubTitle = "This is another string. Please click on '<a href=\"/Home/Status\" target=\"_blank">Here</a>'"
}
}
Run Code Online (Sandbox Code Playgroud)
然后,在我的 Index.csthml 上,我有以下代码:
<label id="title" for="MyTitle">@Myprogram.Common.UiStrings.Title </label>
<label id="title" for="SubTitle">@Myprogram.Common.UiStrings.SubTitle </label>
Run Code Online (Sandbox Code Playgroud)
标题呈现得很好,但我在副标题中定义的链接不会呈现为链接,而是呈现为字符串本身。
有没有办法做到这一点?我想避免对 cshtml 文件中的字符串进行硬编码...
用户 Html.Raw
<label id="title" for="MyTitle">@Myprogram.Common.UiStrings.Title </label>
<label id="title" for="SubTitle">@Html.Raw(Myprogram.Common.UiStrings.SubTitle) </label>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2029 次 |
最近记录: |