Skip to content

Use AJAX requests to modify the Spreadsheet control's content.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-core-spreadsheet-update-document

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spreadsheet for ASP.NET Core - How to use AJAX requests to update document content

You can use AJAX requests to modify the Spreadsheet control's content. In this example, the control sends a POST request after a click on an external button. In response to this request, the control creates a document and edits its cells.

ASP.NET Core Spreadsheet - update the control's content

Overview

Follow the steps below to update the Spreadsheet control's document content once a user clicks a button.

1. Send a POST request to the server

Place the Spreadsheet control in a partial view and reference the view in a markup page. Add a button to this page. In the button's click event handler, get the Spreadsheet's client state and send it with a POST request to the server.

2. Process the request on the server

On the server, get the server-side Spreadsheet object from the client state. Call the object's New method to create an empty document. Use the following properties to access and edit the new document's structural elements:

3. Send a response back to the client

A new document has an empty identifier. The control cannot save such a document and loses its content when you open or create another document. Generate a unique string identifier for this document to be able to save pending changes. Call the SaveCopy method to export the document content to a byte array.

Create a class that models a spreadsheet document. This class should be able to store a document's identifier and content. The example below creates the SpreadsheetDocumentContent class that stores document content as a byte array:

namespace UpdateDocumentUsingAJAX.Models {
    public class SpreadsheetDocumentContent {
        public string DocumentId { get; set; }
        public Func<byte[]> ContentAccessorByBytes { get; set; }
        public SpreadsheetDocumentContent(string documentId, Func<byte[]> contentAccessorByBytes) {
            DocumentId = documentId;
            ContentAccessorByBytes = contentAccessorByBytes;
        }
}

Create an instance of this class and write the generated identifier and exported document content to the instance. Pass it to the PartialView method to create an object that renders the Spreadsheet. Send this object back to the client as a response.

Files to Look At

Documentation

More Examples