I am getting this error when I compile: Error-CS0103 "The name 'HtmlEncode' does not exist in the current context"
I am using Visual Studio 2015 Community edition and MVC.
The code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
namespace MvcMovie.Controllers
{
public class HelloWorldController : Controller
{
//
// GET: /HelloWorld/
public string Index()
{
return "This is my default action...";
}
//
// GET: /HelloWorld/Welcome/
public string Welcome(string name, int numTimes = 1)
{
return HtmlEncoder.Default.HtmlEncode(
"Hello " + name + ", NumTimes is: " + numTimes);
}
}
}
I cannot find HtmlEncoder to add to References.
Can you see what I am doing wrong?
Thanks!
Try this:
HttpUtility.HtmlEncode("Hello " + name + ", NumTimes is: " + numTimes);
you are missing :
using Microsoft.Extensions.WebEncoders;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With