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