第二次没有调用控制器功能

时间:2012-05-24 09:51:09

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-2

我正在研究asp mvc应用程序。 我根据数据库中的数据生成图表。 当我点击go按钮时,我调用了getReportData()函数,该函数从db获取结果并设置图表图像。

当我第一次调用我的功能正常但是在很短的时间内只显示网格数据,我的意思是生成图像的功能不是第二次调用,我试图调试它但是只是第一次我得到调试点不是第二次。

  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 个答案:

答案 0 :(得分:2)

Paven,

这是因为当您启动img click时DOM会发生变化,因此您的bind事件处理程序会被吹走。请尝试使用jquery .on()事件处理程序:

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

这与旧的jquery .live()事件的工作方式类似,即使在刷新DOM时也会保留事件处理程序,直到您发出.off()请求或离开页面为止。

答案 1 :(得分:1)

我认为网址在这里是个问题 的 '/ fetchChartReport?图图表=丿' 您需要在此处提供适当的控制器和操作名称。如果您从另一个页面“fetchGridReport”发布。更好地从隐藏字段中获取网址,如下所示。

var url = $(“#hdnChartUrl”)。val();

$('#span_bar_result img [alt =“Resolved vs UnResolved报告”])。attr('src', url +'?chartType = Bar&amp; from_date ='+ parent。 top。$(“input#from_date”)。val()+'&amp; to_date ='+ parent.top。$(“input#to_date”)。val()+'&amp; report ='+ report +'&amp; subreport ='+ subreport +'&amp; reporttitle =报告由Resolved vs UnResolved&amp; displayformat = 2&amp; filterParamList = no');

现在看到url是动态添加的。