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

解决方案 »

  1.   

    貌似可以的,虽然用public FileResult ExportExcel(string content)更常见些,console.log($("#exporttable").html())有输出么?还有你的content里有html么,如果有,应该会出错的另,从AJAX回复里应该不可以直接下载文件吧
      

  2.   

    正确的写法是
    Request.Form["content"]Request["content"] 是获取querystring
    Request.Form["content"] 到控制器里还是没有数据啊
      

  3.   

    console.log($("#exporttable").html())是有输出的,数据里是有html的 ,我想把整张table都传过去 ,在导出,求指导啊 怎么实现导出视图中的table
      

  4.   

    正确的写法是
    Request.Form["content"]Request["content"] 是获取querystring
    Request.Form["content"] 到控制器里还是没有数据啊
    如果你要传递 Html 内容,要在action 上面 取消 对post 内容的校验:加上
    [ValidateInput(false)]
    [HttpPost]
            public FileResult ExportExcel( FormCollection form )
            {
    }
      

  5.   

    <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" />
      

  6.   

    仅作参考(作生产之用,还要考虑异常什么的等等),用了.NET 4.5/MVC 4
      

  7.   

    正确的写法是
    Request.Form["content"]Request["content"] 是获取querystring
    Request.Form["content"] 到控制器里还是没有数据啊
    如果你要传递 Html 内容,要在action 上面 取消 对post 内容的校验:加上
    [ValidateInput(false)]
    [HttpPost]
            public FileResult ExportExcel( FormCollection form )
            {
    }会报错,应该就死 saucer 大神说的那个吧,检测到有潜在危险的 Request.Form 值
      

  8.   

    换个思路用execCommand的saveas参数也不行,,,,
      

  9.   

      //第一种:使用FileContentResult
                string content=Request["content"];
                byte[] fileContents = Encoding.Default.GetBytes(content);
                return File(fileContents, "application/ms-excel", "课程设计选题情况.xls");
    使用这种 导出的excel中的汉字变成乱码了  有什么解决的好方法