问题描述
1.后台从数据库取出数生成FileResult,正常情况下浏览器可直接导出excel了但是现在想控制View层的按钮,点击导出按钮后禁用按钮,等事件完成再启用就出问题了。后台代码:[HttpPost]publicFileResultIndex(ReportModelmodel){if(!model.ReporType.HasValue){returnnull;}bytereportTypeValue=0;stringreportName=string.Empty;ReportTypeaccountMaster=_reportService.GetReportType(model.ReporType.Value);if(accountMaster==null){returnnull;}else{reportTypeValue=accountMaster.Id;reportName=accountMaster.Name;}bytebusinessTypeValue=0;stringbusinessName=string.Empty;if(model.BusinessType.HasValue){businessTypeValue=model.BusinessType.Value;businessName=_reportService.GetReportBusinessName(reportTypeValue,businessTypeValue);}vargetUser=GetUser();ReportSearchConditionrsc=newReportSearchCondition{ReportName=reportName,BusinessID=businessTypeValue,BusinessName=businessName,BeginTime=model.BeginTime.Value,EndTime=model.EndTime.Value.AddMilliseconds(997),OperaterID=getUser.UserCode,OperaterName=getUser.UserName};Func<ReportSearchCondition,DataSet>func=GetReportMethod(reportTypeValue);stringfileName=string.Format("{0}从{1}到{2}",rsc.BusinessID==0?rsc.ReportName:rsc.BusinessName,Convert.ToDateTime(rsc.BeginTime).ToString("yyMMdd"),Convert.ToDateTime(rsc.EndTime).ToString("yyMMdd"));ExportDataToExcel(func,rsc);returnFile(fileName,"application/vnd.ms-excel");}
2.前台通过Ajax.BeginForm来异步控制,onbegin就执行startFunc脚本禁用导出按钮,onsuccess就执行completeFunc启用导出按钮,但是这个时候,浏览器就不再出现下载EXCEL文件的提示了!!整了一天,希望有高手指点。顺便说下Ajax.BeginForm的UpdateTargetId="Result"能把报表结果导出到id=result这个div下面展示到页面,就是TM不出现下载文件。前台代码:@modelMyj.ELife.Financial.WebUI.Models.ReportModel@{ViewBag.Title="Index";}<divid="content"><fieldset><legend>报表导出</legend><divclass="edit">@using(Ajax.BeginForm("Index","Report",newAjaxOptions{LoadingElementId="message",OnBegin="startFunc",OnSuccess="completeFunc",//UpdateTargetId="Result"})){<tablecellpadding="0"cellspacing="0"class="table_edit"><tr><th>@Html.Encode("报表类型:")</th><td>@Html.DropDownList("ReporType",Model.AvailableReportTypeStatuses)</td><th>@Html.Encode("业务类型:")</th><td>@Html.DropDownList("BusinessType",Model.AvailableBusinessTypeStatuses)</td></tr><tr><th>@Html.Encode("开始时间:")</th><td>@Html.TextBox("BeginTime",null,new{@class="mediumfield",@id="txtBeginTime",onfocus="WdatePicker({dateFmt:'yyyy-MM-ddHH:mm:ss',readOnly:true})"})</td><th>@Html.Encode("截止时间:")</th><td>@Html.TextBox("EndTime",null,new{@class="mediumfield",@id="txtEndTime",onfocus="WdatePicker({dateFmt:'yyyy-MM-ddHH:mm:ss',readOnly:true})"})</td></tr><tr><tdcolspan="4"style="text-align:center;"><inputclass="button_big"type="submit"id="i_Export"value="报表导出"/></td></tr><tr><tdcolspan="4"style="text-align:center;"><divid="message"style="color:Red;display:none;"><imgid="loadingImg"src="../../Content/themes/images/loadingData.gif"/>正在导出...</div></td></tr><tr><tdcolspan="4"style="text-align:center;"><divid="Result"style="color:Red;"></div></td></tr></table>}</div></fieldset></div>@*<scriptsrc="@Url.Content("../../Scripts/My97DatePicker/WdatePicker.js")"type="text/javascript"></script>*@<scriptsrc="@Url.Content("~/Scripts/jquery.validate.min.js")"type="text/javascript"></script><scriptsrc="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"type="text/javascript"></script><scriptsrc="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"type="text/javascript"></script><scripttype="text/javascript">varstartFunc=function(){$('input[id=i_Export]').attr('disabled',true);$('input[id=i_Export]').removeAttr('class');}varcompleteFunc=function(){$('input[id=i_Export]').removeAttr('disabled');$('input[id=i_Export]').attr('class','button_big');$.ajax({type:this.method,url:this.action,data:$(this).serialize(),});}$(document).ready(function(){$('select[id=ReporType]').change(function(){varid=$('select[id=ReporType]').val();//门店余额查询及深圳通明细查询(结算)不需要供应商if(id==2||id==5){$("#BusinessType").empty();$("<option></option>").val("").html("--请选择--").appendTo("#BusinessType");$('select[id=BusinessType]').attr("disabled",true);returnfalse;}$('select[id=BusinessType]').attr("disabled",false);varurl='@Url.Content("~/Report/GetAccountDetails?id=")'+id+"&"+Math.random();$.getJSON(url,function(result){$("#BusinessType").empty();$("<option></option>").val("").html("--请选择--").appendTo("#BusinessType");$.each(result,function(i){$("#BusinessType").append($("<option></option>").val(result[i].SupplierCode).html(result[i].SupplierName))});});});$('#i_Export').click(function(){varreporTypeId=$('select[id=ReporType]').val();if(typeof(reporTypeId)==undefined||reporTypeId==''){alert("请选择报表类型");returnfalse;}//检查选择的业务类型,排除门店余额查询及深圳通明细查询(结算)if(reporTypeId!=2&&reporTypeId!=5){varbussinessId=$('select[id=BusinessType]').val();if(typeof(bussinessId)==undefined||bussinessId==''){alert("请选择业务类型");returnfalse;}}//检查输入的日期是否合法varbeginTime=$('#txtBeginTime').val();varendTime=$('#txtEndTime').val();if(typeof(beginTime)==undefined||beginTime==''){alert("请输入开始时间!");returnfalse;}if(typeof(endTime)==undefined||endTime==''){alert("请输入结束时间!");returnfalse;}varbeginDate=newDate(beginTime.replace(/^(d{4})(d{2})(d{2})$/,"$1/$2/$3"));varendDate=newDate(endTime.replace(/^(d{4})(d{2})(d{2})$/,"$1/$2/$3"));if(beginDate>endDate){alert("开始时间不能大于结束时间!");returnfalse;}});})</script>
解决方案
解决方案二:
人烟稀少,顶一下
解决方案三:
没有高手吗?
解决方案四:
我也遇到这个问题了,lz是怎么解决的呀。。。。。
解决方案五:
马克一下,我也遇到这个问题,求解!
解决方案六:
也许是你的浏览器安全设置的问题