2016-08-01 6 views
0

ajax関数に問題があります。私はコントローラとこのajax関数呼び出しメソッドのメソッドにparamを2回送ろうとします。MVC Ajax関数呼び出しを2回

AJAX:( "EXP")。?

$(document).ready(function() { 


    $(document).on('click', '.exp', function (e) { 

     var st_date = $(this).parent().find('.start').val(); 
     var ed_date = $(this).parent().find('.end').val(); 

     $.ajax({ 


      url: '/Reports/Report_CLeav/', 

      data: { 
       start_date:st_date, 
       end_date:ed_date 
       } 
     }).success(function (data) { 



      }) 

    }); 

}) 
+1

'$(文書).offのように、最初のハンドラを切り離すようにしてください( 'クリック')。click'' – Yang

+0

あなたが.exp''と私たちに要素を表示することができます '(上? –

+0

Html.ActionLink( "Export Report"、 "Report_CLeav"、 "Reports"、新しい{class = "IndexButton exp"、@style = "text-decoration:none; color:white"}) – POL11

答えて

0

$(関数(){

 var st_date = $(this).parent().find('.start').val(); 
     var ed_date = $(this).parent().find('.end').val(); 

     $.ajax({ 


      url: '/Reports/Report_CLeav/', 

      data: { 
       start_date:st_date, 
       end_date:ed_date 
       } 
     }).success(function (data) { 






     }) 

    }); 

0
<th> 
        Start date: @Html.TextBox("start_date", null, new { @class = "dateClass start", id = "StartDate" }) 
        End date: @Html.TextBox("end_date", null, new { @class = "dateClass end", id = "EndDate", @data_toggle = "popover", @data_content = "End date should be greater than Start date. ", @title = "Attention" }) 

        @Html.ActionLink("Export Report", "Report_CLeav", "Reports", new { @class = "IndexButton exp", @style = "text-decoration: none;color:white" }) 
       </th> 

"コントローラ" publicクラスをクリックしてくださいReportsController:コントローラ { // GET:エクスポート public ActionResult Index() { return View(); }

公共ボイドReport_CLeav(日時START_DATE、日時END_DATE?) {文字列パス= HttpContext.Server.MapPath( "〜/ App_Dataに/レポート/ Report_LeavingCompanyHCT.xlsx")。 Models.Report.Report_CompLeav reportcompleav = new Models.Report.Report_CompLeav(); var fileinfo =新しいFileInfo(パス);

 using (ExcelPackage package = new ExcelPackage(fileinfo)) 
     { 

      var currentWorksheet = package.Workbook.Worksheets["HC"]; 

      using (var excelToExport = new ExcelPackage()) 
      { 
       excelToExport.Workbook.Worksheets.Add(currentWorksheet.Name, currentWorksheet); 
       var workBook = excelToExport.Workbook.Worksheets["HC"]; 
       try 
       { 
        workBook = reportcompleav.exportAllEmployeeDataRRecords(workBook,start_date,end_date); 
       } 
       catch (Exception e) 
       { 
        ViewBag.IsError = true; 
       } 


       excelToExport.Save(); 

       Stream stream = excelToExport.Stream; 
       var memoryStream = stream as MemoryStream; 

       Response.Clear(); 
       Response.ContentType = "application/vnd.openxmlformats"; 
       Response.AddHeader("Content-Disposition", 
            "attachment; filename=" + fileinfo.Name); 
       Response.BinaryWrite(memoryStream.ToArray()); 

      } 
     } 

    } 
} 

}

関連する問題