Get Page HTML and Send to Controller

1

Hello,

I'm trying to get all the page html from the tag and send it to my controller, but I'm not getting it, it follows used code.

    function exportarExcel() {
    var url = '@Url.Action("ExportExcel")';
    var html = $("body").html();
    $.ajax({
        url: url,
        data: {
            Html: html,
        },
    });
}

Function on Controller:

    public void ExportExcel(string Html)
    {
        Classes.Export.ToExcelHtml(Response, Html.ToString());

    }
    
asked by anonymous 18.10.2018 / 13:36

1 answer

4

ASP.NET ignored your request for security (XSS, Cross-Site Scripting ). Before the method in the controller, use the ValidateInput attribute:

[ValidateInput(false)]
public void ExportExcel(string Html)
{
   Classes.Export.ToExcelHtml(Response, Html.ToString());       
}

Your JavaScript:

  function exportarExcel() {
    var url = '@Url.Action("ExportExcel")';
    var html = $("body").html();
    $.ajax({
        url: url,
        type: 'POST',
        data: {
            Html: html,
        },
    });
}

Sources:
ASP.NET Request Validation
jquery - Sending HTML to Controller using Ajax POST - Stack Overflow

    
18.10.2018 / 14:16