asp.net-mvc - Controller 函数没有被第二次调用

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

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

当我第一次调用时,我的函数工作正常,但第二次仅显示网格数据,我的意思是生成图像的函数不是第二次调用,我尝试过调试它,但只有第一次我得到调试点不是第二次了。

  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");
        }



    }

提前致谢

最佳答案

帕文,

这是由于当您启动 img 单击时 DOM 发生变化,因此您的绑定(bind)事件处理程序会被破坏。尝试使用 jquery .on() 事件处理程序:

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

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

关于asp.net-mvc - Controller 函数没有被第二次调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10735078/

相关文章:

javascript - 当单元格更改时如何刷新自定义剑道网格过滤器

c# - 设置 MVC ASP.NET 应用程序来执行计划任务 - 实现方法?

asp.net-mvc-3 - KendoGrid 在 kendoTabStrip 中不起作用

asp.net-mvc-2 - MVC 2,将模型显示为文本框

c# - 绑定(bind)请求参数到具体的方法参数

c# - TransactionScope 检查事务是否提交正常

javascript - 通过javascript将包含数组的对象数组传递给MVC Action

asp.net-mvc-3 - Razor 查看 if 语句不正确

jquery - 在 jquery ajax 帖子上使用 mvc 3 进行不显眼的验证时遇到问题

regex - RegularExpressionAttribute - 如何使它对客户端验证不区分大小写?