MVC Ajax函数调用两次

时间:2016-08-01 11:19:56

标签: ajax model-view-controller

我的ajax功能有问题。我想将param发送到控制器上的方法和这个ajax函数调用方法两次。

AJAX:

$(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) {



           })

    });

})

2 个答案:

答案 0 :(得分:0)

$(“。exp”)。click(function(){

        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 :(得分: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 class ReportsController:Controller     {         // GET:导出         公共ActionResult索引()         {             return View();         }

public void Report_CLeav(DateTime?start_date,DateTime?end_date)         {             string path = HttpContext.Server.MapPath(“〜/ App_Data / reports / Report_LeavingCompanyHCT.xlsx”);             Models.Report.Report_CompLeav reportcompleav = new Models.Report.Report_CompLeav();             var fileinfo = new FileInfo(path);

        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());

            }
        }

    }
}

}