2012-05-24 26 views
2

我正在研究asp mvc應用程序。 我正在根據數據庫中的數據生成圖表。 當我點擊去按鈕我有調用getReportData()函數,從數據庫中提取結果並設置圖表圖像。控制器功能不被稱爲secound時間

當我第一次調用我的功能工作正常,但secound時間只有網格數據顯示,我的意思是生成圖像的函數不是第二次調用,我試圖調試它,但只有第一次,我正在調試不是第二次。

function getReportData() { 
     //   debugger; 
     //Enable wait Icon & disable others 


     $('#span_bar_bg').css('display','none'); 
     $('#span_bar_wait').css('display','block'); 
     $('#span_bar_result').css('display','none'); 
     $('#span_pie_bg').css('display','none'); 
     $('#span_pie_wait').css('display','block'); 
     $('#span_pie_result').css('display','none'); 
     var report='ProductNameBatch'; 
     var subreport='Non-FaceBook'; 
     if(report.toLowerCase()=='ctss') 
     { 
     alert('Report is temporarily Un-available'); 
     return; 
     } 

     if (parent.top.$("input#from_date").val() == "" || parent.top.$("input#to_date").val() == "") { 
      alert("Invalid Date Range !!!"); 
      return; 
     } 


     $("#span_grid_bg").css('display','none'); 
     $("#span_grid_view").css('display', 'block'); 



      // "sScrollX": "100%", 
      // "sScrollXInner": "101%", 
      // "bScrollCollapse": true, 


     $('#grid_view').dataTable({ 
      "bAutoWidth": true, 
      "bServerSide": false, 
      "sAjaxSource": "fetchGridReport?&from_date=" + parent.top.$("input#from_date").val() + "&to_date=" + parent.top.$("input#to_date").val() + "&report="+report+"&subreport="+subreport, 
      "bProcessing": true, 
      "bRetrieve": false, 
      "bDestroy": true, 
      "iDisplayLength": 17, 
      "aoColumns": columnList 
     }); 


     $('#grid_view').dataTable().fnAdjustColumnSizing(); 

     //Request for reports 

     debugger; 
      $('#span_bar_result img[alt="Report by Country-Language"]').attr('src','/fetchChartReport?chartType=Bar&from_date=' + parent.top.$("input#from_date").val() + '&to_date=' +parent.top.$("input#to_date").val() + '&report='+report+'&subreport='+subreport+'&reporttitle=Report by Country-Language&displayformat=2&filterParamList=no'); 
      $('#span_pie_result img[alt="Report by Country-Language"]').attr('src','/fetchChartReport?chartType=Pie&from_date=' + parent.top.$("input#from_date").val() + '&to_date=' + parent.top.$("input#to_date").val() + '&report='+report+'&subreport='+subreport+'&reporttitle=Report by Country-Language&displayformat=2&filterParamList=no'); 

     debugger; 
      $('#span_bar_result img[alt="Report by Response"]').attr('src','/fetchChartReport?chartType=Bar&from_date=' + parent.top.$("input#from_date").val() + '&to_date=' +parent.top.$("input#to_date").val() + '&report='+report+'&subreport='+subreport+'&reporttitle=Report by Response&displayformat=2&filterParamList=no'); 
      $('#span_pie_result img[alt="Report by Response"]').attr('src','/fetchChartReport?chartType=Pie&from_date=' + parent.top.$("input#from_date").val() + '&to_date=' + parent.top.$("input#to_date").val() + '&report='+report+'&subreport='+subreport+'&reporttitle=Report by Response&displayformat=2&filterParamList=no'); 

     debugger; 
      $('#span_bar_result img[alt="Report by Resolved vs UnResolved"]').attr('src','/fetchChartReport?chartType=Bar&from_date=' + parent.top.$("input#from_date").val() + '&to_date=' +parent.top.$("input#to_date").val() + '&report='+report+'&subreport='+subreport+'&reporttitle=Report by Resolved vs UnResolved&displayformat=2&filterParamList=no'); 
      $('#span_pie_result img[alt="Report by Resolved vs UnResolved"]').attr('src','/fetchChartReport?chartType=Pie&from_date=' + parent.top.$("input#from_date").val() + '&to_date=' + parent.top.$("input#to_date").val() + '&report='+report+'&subreport='+subreport+'&reporttitle=Report by Resolved vs UnResolved&displayformat=2&filterParamList=no'); 

     debugger; 
      $('#span_bar_result img[alt="Turk Spend by Country($)"]').attr('src','/fetchChartReport?chartType=Bar&from_date=' + parent.top.$("input#from_date").val() + '&to_date=' +parent.top.$("input#to_date").val() + '&report='+report+'&subreport='+subreport+'&reporttitle=Turk Spend by Country($)&displayformat=2&filterParamList=no'); 
      $('#span_pie_result img[alt="Turk Spend by Country($)"]').attr('src','/fetchChartReport?chartType=Pie&from_date=' + parent.top.$("input#from_date").val() + '&to_date=' + parent.top.$("input#to_date").val() + '&report='+report+'&subreport='+subreport+'&reporttitle=Turk Spend by Country($)&displayformat=2&filterParamList=no'); 



     //register call back functionality invoked when result image response complete 
     $('img[id^="img_barchart_result"]').bind('load',function(){ 
      onLoadComplete('bar'); 

     }); 

     $('img[id^="img_piechart_result"]').bind('load',function(){ 
       onLoadComplete('pie'); 
     }); 

    } 

這裏是我的控制功能提前

public FileResult fetchChartReport(SeriesChartType chartType, string from_date, string to_date, string report, string subreport,string reporttitle,string displayformat, string filterParamList) 
    { 
     try 
     { 
      Chart chart = new Chart(); 
      string repportlistid = "chart-" + report.ToLower() + "-" + subreport.ToLower(); 
      //List<string> reportNameList= GetParameterListById(repportlistid); 
      //return View(); 

      reportObject = getReportInstance(report); 
      chart = reportObject.getChartReport(chartType, from_date, to_date, report.ToLower(), subreport.ToLower(), reporttitle,displayformat, filterParamList); 

      MemoryStream ms = new MemoryStream(); 
      chart.SaveImage(ms); 


      return File(ms.GetBuffer(), @"image/png"); 

     } 
     catch (Exception ex) 
     { 
      return File(Server.MapPath(Url.Content("~/Content/dashboard/images/dash_no_data.jpg")), "image/jpg"); 
     } 



    } 

感謝

回答

2

Paven,

這是由於DOM,當你啓動IMG點擊改變,因此你綁定事件處理程序被吹走。嘗試使用jQuery。對()事件處理程序,而不是:

http://api.jquery.com/on/

這部作品以類似的方式老的jQuery .live()事件,該事件處理程序保留在DOM被刷新,直到你甚至當發出.off()請求,或離開頁面。

1

我認爲URL是這裏的問題 「/ fetchChartReport?圖圖表=餡餅」 你需要給這裏適當的控制器和動作名稱。如果您從另一個頁面「fetchGridReport」發佈帖子,那麼最好從下面的隱藏字段中獲取網址。

var url = $(「#hdnChartUrl」)。val();

$( '#span_bar_result IMG [ALT = 「通過解決懸而未決的VS報告」]')。ATTR( 'src' 中,網址 + '?圖圖表=酒吧& FROM_DATE =' + parent.top。$( 「input#from_date」)。val()+'& to_date ='+ parent.top。$(「input#to_date」)。val()+'& report ='+ report +'& subreport ='+ subreport +'& reporttitle =通過已解決的問題與未解決的問題報告& displayformat = 2 & filterParamList = no');

現在看到url是動態添加的。