Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent ViewData content encoding in ASP.Net Core Razor?

This is fragment from View file:

@{
    ViewData["Title"] = "qwerty **Николай**";
}
<div class="row">
<div class="grid-x grid-padding-x">
    <div class="large-12 cell">
        <h1>Николай Петюх</h1>
    </div>        
</div>    

And this is output fragment in browser:

<head>
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>qwerty **&#x41D;&#x438;&#x43A;&#x43E;&#x43B;&#x430;&#x439;**</title>
    <link rel="icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">


        <link rel="stylesheet" href="/lib/foundation/css/foundation.css" />
        <link rel="stylesheet" href="/css/app.css?v=drh6roXOzy8LX0aJC9iKPBtj4DtYf06wh1r9I6IvZA0" />


</head>
<body>

<div class="grid-container">
    <div class="row">
        <div class="grid-x grid-padding-x">
            <div class="large-12 cell">
                <h1>Николай Петюх</h1>
            </div>        
        </div>    
    </div>    
</div>

Anybody knows how to prevent cyrillic characters encoding to &#XXXX;?

like image 794
Mykola Petiukh Avatar asked Nov 28 '17 15:11

Mykola Petiukh


1 Answers

Resolve problem by adding to Startup.cs next code:

services.Configure<WebEncoderOptions>(options =>
            {
                options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
            });

in ConfigureServices class.

like image 135
Mykola Petiukh Avatar answered Oct 22 '22 10:10

Mykola Petiukh