我的应用程序已经使用MVC 3,.net实现.我想点击一个按钮生成一个excel文件.使用Ajax调用控制器操作.我的主要问题是:在文件生成期间,我试图在屏幕上显示图像,让用户知道进入操作.我可以很好地显示图像,但操作完成后我无法隐藏它.我使用的代码是:
Javascript代码:
$("input.DownloadExcelReport").click(function (e) {
e.preventDefault();
var parameter = -- code to fetch parameter value;
var outputViewUrl = (the url is created here);
showLoading(); -- This function displays the image
window.location.href = outputViewUrl;
});
Run Code Online (Sandbox Code Playgroud)
控制器动作代码:
public ActionResult DownExcelReportForAssortment(Guid parameter)
{
try
{
//the contents for the file generation are fetched here..
// Write contents to excel file
if (memoryStream != null)
{
var documentName = "Report.xls";
byte[] byteArrary = memoryStream.ToArray();
return File(byteArrary, "application/vnd.ms-excel", documentName);
}
}
catch (Exception ex) …Run Code Online (Sandbox Code Playgroud)