我正在教自己asp .net核心。我正在通过getting started guide。在我的HelloWorldController中我有这个方法:
public string Welcome(string name, int numTimes = 1)
{
return HtmlEncoder.Default.Encode($"Hello {name}, numTimes: {numTimes}");
}
但是我收到了一个错误:
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'HtmlEncoder' does not exist in the current context TestApp..NETCoreApp,Version=v1.0 c:\Users\administrator\documents\visual studio 2015\Projects\TestApp\src\TestApp\Controllers\HelloWorldController.cs 23 Active
我做错了什么?
答案 0 :(得分:2)
将以下行添加到HelloWorldController:
using System.Text.Encodings.Web;
或者您可以使用以下行替换行return HtmlEncoder.Default.Encode($"Hello {name}, numTimes: {numTimes}");
:
return System.Text.Encodings.Web.HtmlEncoder.Default.Encode($"Hello {name}, numTimes: {numTimes}");
答案 1 :(得分:0)
您需要安装编码器软件包。将鼠标悬停在return语句中的HtmlEncoder上,它将向您显示潜在的修复程序,提示您在线查找并安装此软件包的最新版本。
希望这有助于修复问题。