Spreadsheet Control in Razor Pages

I have looked over many of the posts on using the APS.Net Core Spreadsheet control and have tested the solutions that have been provided.
However they are all for MVC and not Razor Pages.

I am having trouble in converting the MBVC examples over to Razor Pages, not sure on the openurl

Sample.cshtml

<button class="e-btn" onclick="saveToServer()">Save Back to Server</button>
<ejs-spreadsheet id="spreadsheet" openUrl="/Sample?handler=Open" saveUrl="/Sample?handler=Save" created="onCreated">
     <e-spreadsheet-sheets>
        <e-spreadsheet-sheet>
            <e-spreadsheet-ranges>
                <e-data-manager url="/Files/Sample1.xlsx" adaptor="UrlAdaptor" crossdomain=true></e-data-manager>
            </e-spreadsheet-ranges>
        </e-spreadsheet-sheet>
    </e-spreadsheet-sheets>
</ejs-spreadsheet>

<script>
    function onCreated() {

        var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet');
        var request = new XMLHttpRequest();
        request.responseType = "blob";
        request.onload = () => {
            var file = new File([request.response], "Sample1.xlsx");
            spreadsheetObj.open({ file: file });
        }
        request.open("GET", "/Files / " + "Sample1.xlsx");
        request.send();
    }

    function saveToServer() {
        var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet');
        spreadsheetObj.save();
    }
</script>

Sample.cshtml.cs

public IActionResult Open(IFormCollection openRequest)
        {
            OpenRequest open = new OpenRequest();
            open.File = openRequest.Files[0];
            return Content(Workbook.Open(open));
        }

        public string Save(SaveSettings saveSettings)
        {
            ExcelEngine excelEngine = new ExcelEngine();
            IApplication application = excelEngine.Excel;
            try
            {
                // Convert Spreadsheet data as Stream
                Stream fileStream = Workbook.Save<Stream>(saveSettings);
                IWorkbook workbook = application.Workbooks.Open(fileStream);
                var filePath = Startup._env.ContentRootPath.ToString() +  "/Files/Sample1.xlsx";
                FileStream outputStream = new FileStream(filePath, FileMode.Create);
                workbook.SaveAs(outputStream);
                return "Spreadsheet saved in server";
            }
            catch (Exception ex)
            {
                return "Failure";
            }
        }

3 Replies 1 reply marked as answer

SP Sangeetha Priya Murugan Syncfusion Team October 5, 2020 02:23 PM UTC

Hi Sheldon, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your reported your requirement and we woud like to let you know that you have provided the wrong link for OpenUrl and SaveUrl. Need to provide the controller name for open and save functionality in OpenUrl and SaveUrl respectively. So, we would suggest you to provide the controller name for open and save functionality. For more details, please refer the below links. 
 
 
 
 Could you please check the above details and get back to us, if you need any further assistance on this. 
 
Regards, 
Sangeetha M 



SH Sheldon October 5, 2020 06:53 PM UTC

I tried changing the openUrl and saveUrl to what you mentioned from those links it but still does not seem to work.
openUrl="/Sample?handler=Open" to openUrl="Open" and same for saveUrl

I am getting a 404 error on the openUrl regardless of using /Sample?handler=Open or Sample/Open or just Open, the last 2 options seem like they would be for MVC application and not Razor Pages.

How do I utilize the Spreadsheet control in Razor Pages?




SP Sangeetha Priya Murugan Syncfusion Team October 9, 2020 05:43 PM UTC

Hi Sheldon, 
 
Thank you for your patience. 
 
We have checked your reported requirement and it can be achievable in our Spreadsheet. For your convenience, we have prepared the sample based on your requirement. Please find the link below. 
 
 
Could you please check the above sample and get back to us if you need further assistance. 
 
Regards, 
Sangeetha M 


Marked as answer
Loader.
Up arrow icon