简体   繁体   中英

Razor C# output of non-english characters

Razor C# newbe here,

I have the following code:

@foreach(var row in db.Query(selectQueryString))
{                           
@: ["@row.Table1", "@row.Table2", "@row.Table3", "@row.Table4", "@row.Table5", "@row.Table6", "@row.Table7",],                                                   
} 

That loops out content from my database. However since I'm from Sweden I need to use the non-english characters "å, ä, ö" and these do not show correctly.

Looking at what's rendered, here for example "köp" the letter "ö" is replaced by "ö" instead. What i would want is to have the correct letter replacing this, or to know if there is some method I can use to solve this problem.

Using UTF-8

<meta charset="utf-8" />

Thanks in advance!

Your problem is HTML Encoding. Try one of these solutions

@Html.Raw("k&#246;p")
@HttpUtility.HtmlDecode("k&#246;p")
@(new HtmlString("k&#246;p"))
@MvcHtmlString.Create("k&#246;p")

尝试使用Server.HtmlEncode(“您的Unicode文本”)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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