For security reasons, by default, if the HTML content is directly included in the data sent from the client, ASP. NET will automatically start protection, you will receive the following error message
This is certainly a nice design, but in certain special things, if we do need to accept the HTML sent by the client, then we need to make some necessary changes
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Namespace Emreditor.controllers
{
public class Homecontroller:controller
{
Get:home
Public ActionResult Index ()
//{
return View ();
//}
[HttpPost]
[ValidateInput (false)]
Public ActionResult Index ()
{
var req = Request.Form;
Return content (req["content"]);
}
}
}
Then, in Web. config, you also need to configure
<system.web>
<compilation debug= "true" targetframework= "4.5.2"/>
requestvalidationmode= "2.0"/>
</system.web>
Directly accept HTML content fragments sent by the client in the action of ASP.