# ASP.NET Core

> Add the TX Sheet Control spreadsheet editor to ASP.NET Core Razor Pages with the tx-sheet-control Tag Helper, UseTXSheetControlAssets and TXSheetControlOptions.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Getting Started > Spreadsheet Editor > ASP.NET Core
- **2156 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/aspnet-core/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/aspnet-core/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/aspnet-core/llms-full.txt

---

In an ASP.NET Core Razor Pages application, the spreadsheet editor is a Tag Helper. One `tx-sheet-control` element in a Razor page renders the editor and brings along the scripts it needs, with bundled styles isolated inside Shadow DOM, and a script of your own fills the worksheet once the editor is ready.

### Install the Package

Install `TXTextControl.TXSheetControl.AspNetCore` 2.0.0 from the Text Control Private NuGet Feed; [Install the NuGet Packages](https://docs.textcontrol.com/tx-sheet-control/installation/nuget/llms-full.txt) shows how. The package targets .NET 10 and provides the complete browser editor and the static fonts, independently of the Server package.

### Configure the Application

Configure the services and the request pipeline in the application's startup code:

```csharp
using TXTextControl.TXSheetControl.AspNetCore;

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseStaticWebAssets();
builder.Services.AddRazorPages();

var app = builder.Build();
app.UseTXSheetControlAssets();
app.UseStaticFiles();
app.MapRazorPages();
app.Run();
```

The code works as follows:

- `UseStaticWebAssets` enables static web assets. The font and language assets of the editor are part of the package's static web assets.
- `AddRazorPages` and `MapRazorPages` add Razor Pages and map their endpoints.
- [UseTXSheetControlAssets](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontrolassetextensions/usetxsheetcontrolassets-method/llms-full.txt) rejects private and debugging paths before the static-file or static-web-asset endpoint middleware executes. Call it before `UseStaticFiles`, as the code does.
- `UseStaticFiles` serves the static files of the application, such as `wwwroot/sales.js`.

### Register the Tag Helper

In `Pages/_ViewImports.cshtml`:

```cshtml
@using TXTextControl.TXSheetControl.AspNetCore
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, TXTextControl.TXSheetControl.AspNetCore
```

The last line registers [TXSheetControlTagHelper](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontroltaghelper/llms-full.txt), the Tag Helper of the package, which renders a browser editor for the `tx-sheet-control` element.

### Add the Editor to a Razor Page

Add the editor to a Razor page:

```cshtml
@page
@{
    var options = new TXSheetControlOptions { License = Environment.GetEnvironmentVariable("TX_SHEET_LICENSE") };
}

<tx-sheet-control id="sales" height="640" options="options" />

<script src="~/sales.js"></script>
```

The `tx-sheet-control` element renders the editor with the ID `sales` and a [Height](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontroltaghelper/height-property/llms-full.txt) of 640. The `script` element loads `sales.js`, which the next section creates.

> Important
>
> **Stylesheet and Scripts.** The Tag Helper automatically includes its browser script and initializer. The editor installs its bundled stylesheet inside its shadow root. Do not add those package references manually.

The Tag Helper emits the assets once per request, including on pages with multiple editors. Their URLs honor virtual application paths and static-file cache versions.

### Fill the Worksheet From JavaScript

In `wwwroot/sales.js`:

```javascript
document.addEventListener('txsheetcontrolready', event => {
    if (!(event instanceof CustomEvent) || !(event.target instanceof HTMLElement) || event.target.id !== 'sales') return;

    const sheet = event.detail.workbook.sheets.at(0);
    sheet.range('A1:B3').setValues([
        ['Item', 'Amount'], ['Hardware', 120], ['Software', 80]
    ]);

    sheet.cell('B4').setFormula('=SUM(B2:B3)');
});
```

The code works as follows:

- The handler listens on `document` for the `txsheetcontrolready` event of the editor.
- It returns unless the event is a `CustomEvent` whose target is the element with the ID `sales`, so it handles this one editor only.
- `event.detail` is the editor. [sheets](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/workbook/sheets-property/llms-full.txt) and [at](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/sheetcollection/at-method/llms-full.txt) return the first worksheet of its workbook.
- [range](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/range-method/llms-full.txt) and [setValues](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/range/setvalues-method/llms-full.txt) write the headings `Item` and `Amount` and two items into A1:B3.
- [cell](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/cell-method/llms-full.txt) and [setFormula](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/cell/setformula-method/llms-full.txt) put the formula `=SUM(B2:B3)` into B4.

After initialization, use `event.detail` or `TXTextControl.TXSheetControl.getControl('sales')` to reach the editor; [getControl](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/getcontrol-function/llms-full.txt) takes the ID or the element. Subscribe to `txsheetcontrolerror` for initialization failures.

> Important
>
> **Register Handlers Early.** Register ready handlers during page loading, before initialization completes.

### Pass Options to the Editor

Pass [TXSheetControlOptions](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontroloptions/llms-full.txt) through the `options` attribute, the [Options](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontroltaghelper/options-property/llms-full.txt) property of the Tag Helper. They set:

- **The locale** with [Locale](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontroloptions/locale-property/llms-full.txt).
- **The theme** with [Theme](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontroloptions/theme-property/llms-full.txt).
- **The visible control areas** with [Areas](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontroloptions/areas-property/llms-full.txt).
- **The dashboard viewer mode** with [DashboardMode](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontroloptions/dashboardmode-property/llms-full.txt). The viewer permits dashboard filters and drill-down without worksheet navigation or authoring.

### How Fonts and Assets Are Deployed

The default fonts use the packaged static catalog. No processing-server or font-service registration is required. A normal build and publish retain the editor assets.

### Try OpenDocument Workbooks in the Razor Sample

The repository’s Razor workbook sample opens `.xlsx`, `.ods` and `.txwb` files. Choose **Save ODS** to download an OpenDocument spreadsheet with optional document properties and original-package preservation. The Pivot Tables and Barcodes samples also offer **Save ODS**, and the mail-merge sample includes ODS in **Download format**. The server PDF sample can load its ODS invoice template before merging and rendering the invoice.

These operations use the same load and save API as XLSX, with `StreamType.OpenDocumentSpreadsheet` selecting ODS.

### Next Steps

- [ASP.NET Core Applications](https://docs.textcontrol.com/tx-sheet-control/deployment/aspnet-core/llms-full.txt): build, publish and deploy the Razor editor application.
- [Custom Fonts](https://docs.textcontrol.com/tx-sheet-control/deployment/custom-fonts/llms-full.txt): deploy fonts of your own for the editor.

Set `TX_SHEET_LICENSE` to the contents of your license file, `tx-sheet-control.license`, before starting the application. The Razor page supplies it through `TXSheetControlOptions.License`.

---

## Nearby

- **Previous:** [TypeScript](https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/typescript/llms-full.txt)
- **Next:** [Angular](https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/angular/llms-full.txt)
