mvc模式如何讲视图中的一个table传到控制器 导出为excel,求大神帮助

mvc模式怎么讲视图中的一个table传到控制器 导出为excel,求大神帮助
view中我用jquery操作
<script type="text/javascript">
    $(
    function () {
        $("#btnExport").click(function () {
            console.log($("#exporttable").html())

            //            $.ajax({
            //                type: 'POST',
            //                url: "/Admin/ExportExcel",
            //                data: { content: "测试数据" },
            //                success: function (data) { },
            //                dataType: "json"
            //            });

            $.post("/Admin/ExportExcel",
            { content: $("#exporttable").html() },
             "json"
             ); //post end

        } //click end
        );
    }
    );
</script>

控制器中导出excel
[HttpPost]
        public FileResult ExportExcel( FormCollection form )
        {
             //第一种:使用FileContentResult
            string content=Request["content"];
            byte[] fileContents = Encoding.Default.GetBytes(content);
            return File(fileContents, "application/ms-excel", "课程设计选题情况.xls");
             
             //第二种:使用FileStreamResult
             //var fileStream = new MemoryStream(fileContents);
             //return File(fileStream, "application/ms-excel", "fileStream.xls");
 
             //第三种:使用FilePathResult
             //服务器上首先必须要有这个Excel文件,然会通过Server.MapPath获取路径返回.
             //var fileName = Server.MapPath("~/uploads/选题信息导入模板.xls");
             //return File(fileName, "application/ms-excel", "fileName.xls");
        }

Request["content"]获取不到数据,,,,,大神给看看,或者有什么好的方法,教一下
------解决思路----------------------
引用:
Quote: 引用:

Quote: 引用:

             //第一种:使用FileContentResult
            string content=Request["content"];
Request["content"]获取不到数据

正确的写法是
Request.Form["content"]

Request["content"] 是获取querystring


Request.Form["content"] 到控制器里还是没有数据啊

如果你要传递 Html 内容,要在action 上面 取消 对post 内容的校验:

加上
[ValidateInput(false)]
[HttpPost]
        public FileResult ExportExcel( FormCollection form )
        {
}

------解决思路----------------------
<div id="exporttable">
<table >
    <tr>
        <td>1</td>
        <td>2</td>
    </tr>
    <tr>
        <td>3</td>
        <td>4</td>
    </tr>
</table>
    </div>
<button id="btnExport">Export</button>
<iframe id="export" name="export" style="display:none"></iframe>
<form name="excel" method="post" action="/Home/ExportExcel" target="export">
    <input type="hidden" name="content" id="content" />
</form>
<script type="text/javascript">
    $(
    function () {
        $("#btnExport").click(function () {
            console.log($("#exporttable").html());
            $("#content").val($("#exporttable").html())
            document.forms["excel"].submit();
        } //click end
        );
    }
    );
</script>


controller.cs:
 [HttpPost]
        [ValidateInput(false)] 
        public FileResult ExportExcel(string content)
        {
            //第一种:使用FileContentResult
            //string content = Request["content"];
            byte[] fileContents = Encoding.Default.GetBytes(content);
            return File(fileContents, "application/ms-excel", "课程设计选题情况.xls");
}

web.config:
  <system.web>
    <httpRuntime targetFramework="4.5" requestValidationMode="2.0" />