HtmlEncoder Error in Asp.Net MVC 5

I get this error when compiling: Error-CS0103 "The name" HtmlEncode "does not exist in the current context"

I am using Visual Studio 2015 Community Edition and MVC.

Code:

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 can not find the HtmlEncoder link for the links. Do you see what I'm doing wrong?

Thanks!

+4
source share
4 answers

Try the following:

    HttpUtility.HtmlEncode("Hello " + name + ", NumTimes is: " + numTimes);
+3
source

you are lacking:

using Microsoft.Extensions.WebEncoders;
+3
source

, , . . , . !

, - .

Thanks to everyone who tried to help me !!!

0
source

In MVC Core I had to use

using System.Text.Encodings.Web;

before HtmlEncoder will work. I also use VS 2017 RC and try to follow the MvcMovie tutorial.

0
source

Source: https://habr.com/ru/post/1618659/


All Articles