如何将乌克兰文本转换为微数据?

huangapple go评论77阅读模式
英文:

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中的文本是正常的,但我得到了这个结果

如何将乌克兰文本转换为微数据?

而不是我的乌克兰文本,显示了奇怪的字符тест
还有一些可能有帮助的其他事项:

  1. 如果不通过变量输入乌克兰文本,那么一切都会正常显示。
  2. 英文文本无论如何都可以正常显示。

我想使用传递给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 тест
There are a couple of other things that might help:

  1. If you enter the Ukrainian text not through a variable, then everything is displayed normally
  2. 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)"

huangapple
  • 本文由 发表于 2023年6月27日 19:20:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定