IE中的MVC中的Excel导出不允许打开多个窗口

| 这是继承自ActionResult的ExcelExport操作:
public class ExcelResult<Model> : ActionResult
    {
        string _fileName;
        string _viewPath;
        Model _model;
        ControllerContext _context;

        public ExcelResult(ControllerContext context, string viewPath, string fileName, Model model)
        {
            this._context = context;
            this._fileName = fileName;
            this._viewPath = viewPath;
            this._model = model;
        }
         protected string RenderViewToString()
        {
            if (!_viewPath.EndsWith(\".aspx\"))
            {
                return _viewPath;
            }
            using (var writer = new StringWriter())
            {
                var view = new WebFormView(_context, _viewPath);
                var vdd = new ViewDataDictionary<Model>(_model);
                var viewCxt = new ViewContext(_context, view, vdd, new TempDataDictionary(), writer);
                viewCxt.View.Render(viewCxt, writer);
                return writer.ToString();
            }
        }
        void WriteFile(string content)
        {
            HttpContext context = HttpContext.Current;
            context.Response.Clear();
            context.Response.AddHeader(\"content-disposition\", \"attachment;filename=\\\"\" + _fileName + \"\\\"\");
            context.Response.Charset = \"\";
            //context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.ContentType = \"application/ms-excel\";
            context.Response.Write(RemoveImages(content));
            context.Response.End();
        }

        public override void ExecuteResult(ControllerContext context)
        {
            string content = this.RenderViewToString();
            this.WriteFile(content);
        }

        public static string RemoveImages(string html)
        {
            StringBuilder retval = new StringBuilder();
            using (StringReader reader = new StringReader(html))
            {
                string line = string.Empty;
                do
                {
                    line = reader.ReadLine();
                    if (line != null)
                    {
                        if (!line.StartsWith(\"<img\"))
                        {
                           retval.Append(line); 
                        }
                    }

                } while (line != null);
            }
            return retval.ToString();
        }
    }
导出工作正常,但仅在IE中(在FF中有效),如果导出,则选择打开文件而不是保存文件,然后立即再次单击“导出”,它将尝试打开具有相同名称的另一个文件,因此在关闭工作文档之前,Excel不允许您这样做。 但是,在FF中,名称仅添加一个整数,每次单击导出时该整数将递增1。 我必须怎么做才能在IE中实现相同的功能?     
已邀请:
我遇到了同样的问题,开箱即用,您无法做任何事情,因为这是IE和Excel处理此问题的方式。您也无法识别出已经打开了相同名称的文件。但是,您可以使用JavaScript或用户会话来标识用户已在一个时间段内加载了导出,并在服务器端更改了此下载的文件名。经过两天的搜索和邮寄,这对我有用。     

要回复问题请先登录注册