Table of Contents

C#, Razor & Dynamic Code

When you implement solutions using 2sxc, most of your server-side code will be written in C#.

you are here (click to zoom) - discover the stack

C# Files in 2sxc Apps

You will create many dynamic .cs or .cshtml files in the App folder:

  1. Razor components and shared Razor views
  2. WebApi Controllers (*Controller.cs files in the api folder)
  3. Shared code (*.cs files in any folder)

These files are in your App folder as Dynamic Code and have three core features:

  1. The source code can be changed at any time
  2. Changes are immediately live without restarting the CMS
  3. Cool APIs 😎 help you work with dynamic data (Entities)

Quick Example

The variable person in the following Razor template is a Dynamic Entity - meaning that it can have different properties depending on the configuration. In this case it seems to have FirstName, LastName and Gender.

<div @Edit.Toolbar(person)>
  @person.FirstName @person.LastName - @Text.First(person.Gender, "unknown")

The code first creates a div tag which would show a hover-toolbar (to admins only) for editing the person. It then shows the names and the gender - which if not determined will show as unknown.


This kind of code is easy understand for people who know HTML. It's also very easy to customize if you need a different output - since it's basically HTML and placeholders.

What's Where

This documentation contains the following sections

  1. Dynamic Data Everything you need to understand how data, especially dynamic data, works in 2sxc.
  2. Dynamic Code The shared API on all Dynamic Code - Razor, WebApi or other.
  3. Razor The APIs special to Razor templates
  4. Web API Everything you need to know to create/customize Web API Controllers
  5. External API Guides you to access 2sxc-instances on the server from the Theme, WebForms or other MVC components

Important APIs when Working with Content-Items/Data

TODO: this must be moved elsewhere

  1. DataSource and DataStream, the core concept for data read/processing/delivery
    1. List of all DataSource Objects
    2. how to create custom data sources