I'm encountering a difficult to troubleshoot issue with a Kendo Grid apparently crashing when I attempt to export its contents to an excel file. I've successfully set up Kendo Grids to export to excel before, and my code here is very closely based on other solutions I've had in similar projects. Below is the widget code:
@(
Html.Kendo().Grid(Model.Groups)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(c => c.SamAccountName).Title("SamAccount").Width(250).HeaderHtmlAttributes(new { style = "font-weight: bold" });
columns.Bound(c => c.DistinguishedName).Title("Full Name").Width(400).HeaderHtmlAttributes(new { style = "font-weight: bold" });
columns.Bound(c => c.IsSecurityGroup)
.Width(75)
.Title("Security Group?")
.ClientTemplate("#= IsSecurityGroup ? 'Yes' : 'No' #")
.HeaderHtmlAttributes(new { style = "font-weight: bold" });
})
.Sortable()
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple)
.Type(GridSelectionType.Cell))
.Navigatable()
.AllowCopy(true)
.ToolBar(tools =>
{
tools.Custom().Text("Copy to Clipboard").HtmlAttributes(new { id = "copyButton" });
tools.Excel();
tools.Search();
}).Excel(excel =>
{
excel.FileName(Model.SearchString + "GroupsExport_" + DateTime.Now.Date.ToShortDateString() + ".xlsx");
excel.AllPages(true);
excel.ForceProxy(true);
excel.ProxyURL(Url.Action("ExcelExportSave", "Home"));
})
)
And below is the corresponding action in my HomeController:
[HttpPost]
public ActionResult ExcelExportSave(string contentType, string base64, string fileName)
{
var fileContents = Convert.FromBase64String(base64);
return File(fileContents, contentType, fileName);
}
Behavior
The Grid will correctly load, and allow the user to search, sort, scroll, etc. However upon clicking the Export to Excel button the widget will enter a loading animation and then spin forever. The rightmost IsSecurityGroup column will also appear to be duplicated, but I think this is a visual glitch as I'm not actually seeing an additional column be created in the page elements, this visual glitch goes away if I add "Scrollable".
My breakpoint in the ExcelExportSave() controller action is not being hit, and if I check the network tab it does not appear that a network request is even being made.
There are no errors or warnings printed to the browser console.
Troubleshooting steps I've tried:
- Changing the controller for the ExcelExportSave action and also making the action [Anonymous]
- Simplifying the Grid by removing the client-templates, dynamic filename, and custom button.
- Removed other JS functions from the page (there aren't many, this is a pretty simple page and shouldn't have much conflicting logic)
- Verified that the ViewModel values are not null and as expected on pageload
- I have generally tried adjusting some of the Excel configuration options, but none of these seem to alter the behavior.
Kendo otherwise appears to be correctly imported into the project and I am not experiencing other issues.
My Environment and Project
This is an ASP.NET Core 8 MVC project being run in Visual Studio 2022 on a Windows laptop. The project does use Microsoft Identity authentication and I am developing by running it on Localhost.
Any help that anyone can provide would be greatly appreciated.