将已检查的rowid从视图传递到控制器不起作用

时间:2015-04-07 15:19:16

标签: javascript asp.net-mvc-4 infragistics

实际上这个问题已经被问到,但在我的情况下,没有给出解决方案。     所以我有一个带有复选框的infragistic网格,并根据检查的行我将行索引发送到controller.Am在控制器中获取索引但是该方法不起作用。

请帮我解决这个问题。提前致谢

以下是代码:

视图:

<script type="text/javascript">
    $('#save-selected-rows-button').on('click', function () {
        var $grid = $('#grid');
        var checkedRows = $grid.igGridSelection("selectedRows");
        var indexes = $.map(checkedRows, function (checkedRow) {
            return checkedRow.index;
        });

        $.ajax({
            type: 'POST',
            url: '@Url.Action("ExportGPAttribute", "Export")',
            dataType: 'json',
            contentType: "application/json;",
            data: JSON.stringify(indexes),
            success: function (data) { console.log(data); },
            failure: function (errMsg) {
                console.log(errMsg);
            }
        });
    });
</script>

控制器:

  public ActionResult ExportMasterData(List<string> checkedRowsIndexes)
        {
            if (ModelState.IsValid)
            {
                //workbook creation
                Workbook currentWorkbook = new Workbook();

                ///region
                if (checkedRowsIndexes != null && checkedRowsIndexes.Contains("0"))
                { //export to excel}
if(checkedRowsIndexes.Contains("1"))
{//export to excel}
return View();
}
else
return View();

导出到Excel代码:

if (checkedRowsIndexes != null && checkedRowsIndexes.Contains("0"))
            {
                var service_region = ObjectFactory.GetInstance<IRegionControllerService>();
                var collection_region = service_region.GetRegionViewModel().ToList();



                Worksheet regionsheet = currentWorkbook.Worksheets.Add("Region");
                foreach (var cell in regionsheet.GetRegion("A1:C1"))
                {
                    cell.CellFormat.FillPattern = FillPatternStyle.Solid;
                    cell.CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
                }

                regionsheet.Rows[0].Cells[0].Value = "Region Name";
                regionsheet.Rows[0].Cells[1].Value = "Region Code";
                regionsheet.Rows[0].Cells[2].Value = "Status";

                regionsheet.Columns[0].Width = 6100;
                regionsheet.Columns[1].Width = 3000;
                regionsheet.Columns[2].Width = 6100;

                int i = 1;
                foreach (Region items in collection_region)
                {

                    regionsheet.Rows[i].Cells[0].Value = items.gp_name;
                    regionsheet.Rows[i].Cells[1].Value = items.gp_RegionCode;
                    regionsheet.Rows[i].Cells[2].Value = items.Status;
                    i++;
                }
            }

            Response.Clear();
            Response.AppendHeader("content-disposition", "attachement; filename=Master Data.xlsx");
            Response.ContentType = "application/octet-stream";
            currentWorkbook.SetCurrentFormat(WorkbookFormat.Excel97To2003);
            currentWorkbook.Save(Response.OutputStream);
            Response.Flush();
            Response.End();

1 个答案:

答案 0 :(得分:0)

您认为问题在于导出代码吗?您可以共享它以便进行调查。在“顺利通过代码”之后,您是否收到任何错误?