0

Actually this problem is asked already but in my case no solution given are working. So i have a infragistic grid with check-boxes and based on the row checked i am sending the row-indexes to controller.Am getting indexes in controller but then the method is not working.

Please help me with this. Thanks in advance

Below is the code:

view:

<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>

controller:

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

Export to excel code:

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();
Sonal B
  • 11
  • 4
  • 2
    'method is not working' is a bit vague. Could you specify 'not working' please? Is the data being POSTed to the controller? – Scott Rickman Apr 07 '15 at 15:22
  • yes, the data is posted to the controller meaning am getting the indexes and it is going to the 'if' condition,which contain export to excel code.It goes smooth through the code but export doesn't happen. Although the same export code is used at many other places and it works fine there. – Sonal B Apr 08 '15 at 07:12
  • It's still difficult to understand what the issue is here. You say no errors but what is actually wrong? Does the user get a Save/Download dialog in their browser? Is the attachment emtpy? – Scott Rickman Apr 08 '15 at 10:33
  • That is the problem am not getting any Save/Download dialog in the browser. – Sonal B Apr 08 '15 at 11:14
  • See the answers in this question: http://stackoverflow.com/questions/5826649/returning-a-file-to-view-download-in-mvc. You should probably edit your question too and add the correct tags and neither relate to the actual issue. – Scott Rickman Apr 08 '15 at 11:20

1 Answers1

0

Well don't you think problem lies in the exporting code ? You can share it so that it can be investigated. Do you receive any errors after "going smooth through code" ?