Code Monkey home page Code Monkey logo

asp-net-core-spreadsheet-update-document's Introduction

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

asp-net-core-spreadsheet-update-document's People

Contributors

adelordm avatar svetlanamikheeva avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.