英文:
How can I transfer text in Ukrainian to microdata?
问题
我有一个难以理解的问题。我正在制作一个ASP.NET网站,想要在我的网站上使用微数据。
我有以下用于HTML代码的微数据
@model ListPlatformsVM
@section Microdata {
<script type="application/ld+json">
{
"@@context": "https://schema.org/",
"@@type": "BreadcrumbList",
"itemListElement": [
{
"@@type": "ListItem",
"position": "1",
"name": "@Model.str",
"item": "@Url.GetRouteUrl(EReviewerRoute.HomePage)"
},
{
"@@type": "ListItem",
"position": "2",
"name": "тестовий текст",
"item": "@Url.GetRouteUrl(EReviewerRoute.Platforms)"
}
]
}
</script>
}
正如你所看到的,我正在将@Model.str变量从模型传递给微数据。str是string类型(UTF-16)。通过断点,可以清楚地看到str中的文本是正常的,但我得到了这个结果
而不是我的乌克兰文本,显示了奇怪的字符тест
。
还有一些可能有帮助的其他事项:
- 如果不通过变量输入乌克兰文本,那么一切都会正常显示。
- 英文文本无论如何都可以正常显示。
我想使用传递给HTML代码的变量显示乌克兰文本。请帮助我,提前感谢。
英文:
I have an incomprehensible problem. I'm making an ASP.NET site and I want to stretch microdata to my site.
I have the following microdata for HTML code
@model ListPlatformsVM
@section Microdata {
<script type="application/ld+json">
{
"@@context": "https://schema.org/",
"@@type": "BreadcrumbList",
"itemListElement": [
{
"@@type": "ListItem",
"position": "1",
"name": "@Model.str",
"item": "@Url.GetRouteUrl(EReviewerRoute.HomePage)"
},
{
"@@type": "ListItem",
"position": "2",
"name": "тестовий текст",
"item": "@Url.GetRouteUrl(EReviewerRoute.Platforms)"
}
]
}
</script>
}
As you can see, I am passing the @Model.str variable from the model to the microdata. str is of type string (UTF-16). By breakpoints it is clear that the text in str is normal, but I get this result
Instead of my text in Ukrainian, strange characters are displayed &#x442;&#x435;&#x441;&#x442;
There are a couple of other things that might help:
- If you enter the Ukrainian text not through a variable, then everything is displayed normally
- English text is displayed normally anyway
I want to display Ukrainian text using a variable passing it to the html code. Please help me, thanks in advance
答案1
得分: 1
尝试使用 HtmlHelper.Raw
方法:
> 将HTML标记包装在HtmlString
中,而不对指定的值进行HTML编码。
"name": "@Html.Raw(Model.str)"
英文:
Try using HtmlHelper.Raw
method:
> Wraps HTML markup in a HtmlString
, without HTML-encoding the specified value.
"name": "@Html.Raw(Model.str)"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论