C# MVC HTML to EXCEL not working
<p>I had a controller method to convert html to excel which worked fine when it was not a web method. But stopped working when the html string got too large. I converted it to a web method which I call via jQuery. It passes the data to the method, but no longer creates the Excel file. The code within the method has not changed. The only difference is the way I call it and the [HttpPost] decoration. The code follows:</p>

<pre><code>    [HttpPost]
    [ValidateInput(false)]
    public void ExportExcel(string aContent)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append(aContent);

        Response.ClearContent();
        Response.ContentType = "application/vnd.ms-excel";
        Response.AddHeader("Content-Disposition", "attachment; filename=ProjectData.xls");
        Response.Write(sb);
        Response.End();
    }
</code></pre>

<p>And this is the jQuery stuff:</p>

<pre><code>// namespace
var excel = excel || {};

$(document).ready(function () {
    $('#ExcelUrl').on('click', function () {
        var table = $('#tableName').val();
        var content = $('#' + table).html();
        excel.utilFunctions.exportToExcel(content);
    });
});

excel.utilFunctions = (function ($) {
    var exportToExcel = function (content) {
        $.ajax({
            url: "/Home/ExportExcel",
            type: "POST",
            data: { aContent: content }
        }).done(function(data) {
            alert(data);
        }).fail(function(error) {
            alert(error.responseText);
        });
    };

    //public functions
    return {
        exportToExcel: exportToExcel
    };
})(jQuery);
</code></pre>

<p>Any help is appreciated. </p>