MVC .net内核不正确显示特殊字符 [英] MVC .net core is not displaying special characters correctly

查看:375
本文介绍了MVC .net内核不正确显示特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @model MvcSearch.Models.SearchModel 

@ {
ViewData [Title] =索引;
}

< h2> Buscador deInformación< / h2>

< div class =row>
@ Html.Partial(SearchBox,Model.Search)
< hr />
< div class =container>
< div class =col-md-10>

< div id =results>
@if(Model.Results.Count()== 0)
{
< p>没有hay nada que mostrar,¡busca algo!< / p>
}
< / div>
< / div>
< / div>
< / div>

一切都是工作薄荷,而不是ó和¡符号,它显示了这个字符:



从来没有发生过这种情况,这是我的第一个.net核心项目。



O寻找可能的解决方案此处 here 和其他类似的。但是没有一个完全解决我的环境。



我尝试了第二个链接,但我有一些问题。




  • 对System.Text.Encoding(4.3.0)和System.Text.Encoding.CodePages(4.3.0)的引用均标有警告图标,但是在使用Nuget软件包时不会显示错误或警告经理

  • 我很明白我必须使用这一行



    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) p>




但是不知道在startup.cs中究竟在哪里?




  • 我不知道这是什么意思




一个Encoding.GetEncoding重载来检索编码。
Encoding.GetEncoding方法将调用相应的
EncodingProvider.GetEncoding方法来确定是否可以提供
所请求的编码。


我甚至不确定这是解决这个问题的正确方法。我也红色的脚手架视图文件内置的编码不同于手动创建的文件。我应该创建新的空的查看文件并将文本复制到这些新文件中吗?

解决方案

然而,这一点,对我来说似乎都不够容易。他们从注册错误到注册未定义到网站的编码对象。但是,我通过这样做这样做:



只需使用记事本++或任何其他有能力的文本编辑器打开视图文件。检查它是否以ANSI编码,并将其转换为UTF-8。



运行您的应用程序,一切都将顺利运行。


I have a very simple view in an MVC .net core web site.

@model MvcSearch.Models.SearchModel

@{
    ViewData["Title"] = "Index";
}

<h2>Buscador de Información</h2>

<div class="row">
    @Html.Partial("SearchBox", Model.Search)
    <hr />
    <div class="container">
        <div class="col-md-10">

            <div id="results">
                @if (Model.Results.Count() == 0)
                {
                    <p>No hay nada que mostrar, ¡busca algo!</p>
                }
            </div>
        </div>
    </div>
</div>

Everything is working mint, however instead of the ó and the ¡ symbol, it shows this character: �

Never before happened this to me, and this is my first .net core project.

O looked for possible solutions here and here and others similar. But none quite addresses exactly my environment.

I tried the second link but I have some problems.

  • Both references to System.Text.Encoding(4.3.0) and System.Text.Encoding.CodePages(4.3.0) are marked with a warning icon, however neither showed errors or warning during installation using Nuget Package Manager
  • I quite understand I have to use this line

    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

But don't know where exactly, in startup.cs?

  • I don't know what this means either

Call an Encoding.GetEncoding overload to retrieve the encoding. The Encoding.GetEncoding method will call the corresponding EncodingProvider.GetEncoding method to determine whether it can supply the requested encoding.

I'm not even sure this is the correct way of solving this. I also red that the scaffolded view files where built in an encoding different than the manually created files. Should I just create new empty View files and copy text into those new ones?

解决方案

Yet, there are plenty of answers realted to this, none of them seem easy enough for me. They rnage from registering bugs to registering encoding objects inplaces not defined to web sites. However, I sovled this by doing this:

Simply open the view file in notepad++ or any other capable text editor. Check it is encoded in ANSI, and convert it to UTF-8.

Run your app and everything will work smooth.

这篇关于MVC .net内核不正确显示特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆