C#MVC返回问题(excel和view)

C#MVC返回问题(excel和view),c#,asp.net-mvc,excel,post,view,C#,Asp.net Mvc,Excel,Post,View,我有两个问题 第一: 我有一个绑定了此函数的a href $('#tblReports tbody').on('click', '.btnViewReportExcel', function (e) { $.ajax({ url: urlExcel, type: 'POST', data: { initDate: initDate,

我有两个问题 第一: 我有一个绑定了此函数的a href

$('#tblReports tbody').on('click', '.btnViewReportExcel', function (e) { 
            $.ajax({
                url: urlExcel,
                type: 'POST',
                data: {
                    initDate: initDate,
                    finalDate: finalDate
                }
            });
        });
在控制器中,我有:

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ComissionReport(DateTime initDate, DateTime finalDate)
        {
            var result = things to do;
            return View(result);
        }
我的问题是a href没有返回加载的html,而是在post中返回文本 如何返回加载了此数据的页面重新加载

第二个问题是: 我有一个a href调用的函数:

        [HttpPost]
        public ActionResult GenerateExcel(DateTime initDate, DateTime finalDate)
        {

                MemoryStream ms = data Generated by function

                if (ms != null)
                {
                    ms.Seek(0, SeekOrigin.Begin);
                    return File(ms, @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", "Test.xlsx");
                }
            return new EmptyResult();
        }
但是问题和上面一样,post返回文本形式的excel,我想返回下载文件

有人能解决这个问题吗? 感谢您的帮助,并为我糟糕的英语感到抱歉首先:我有一个绑定了此函数的a href

为什么要打电话?呈现的HTML以jqXHR的形式返回,您可以通过这种方式获得此结果

var result = $.ajax(url: urlExcel ...
但我认为这不是你想要的。您只需执行以下操作即可重定向:

window.location=urlExcel+“/”+您可以在此处输入参数

或者通过AJAX获取HTML内容

$.get(urlExcel, { param1: "value", ... } function(data) { alert(data); });
>>第二个问题是:我有这个函数,也是由a href调用的

您应该指定内容处置标题,如“附件”;filename=“your file name””下载文件,无需预览或其他任何内容,您可以使用“应用程序/八位字节流”作为内容类型标题值

Response.Headers.Add("Content-Disposition", "attachment ...));

return File(ms, ...

你试过这样吗?url:'/urlExcel',我已经解决了问题,解决方案很简单,我使用了window.open和window.location谢谢您的帮助!在javascript中打开window.open,谢谢您的帮助!