C#, Razor & Dynamic Code
When you implement solutions using 2sxc, most of your server-side code will be written in C#.
C# Files in 2sxc Apps
You will create many dynamic .cs
or .cshtml
files in the App folder:
- Razor components and shared Razor views
- WebApi Controllers (
*Controller.cs
files in theapi
folder) - Shared code (
*.cs
files in any folder)
Tip
These files are in your App folder as Dynamic Code and have three core features:
- The source code can be changed at any time
- Changes are immediately live without restarting the CMS
- 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")
</div>
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
.
Note
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
- Dynamic Data Everything you need to understand how data, especially dynamic data, works in 2sxc.
- Dynamic Code The shared API on all Dynamic Code - Razor, WebApi or other.
- Razor The APIs special to Razor templates
- Web API Everything you need to know to create/customize Web API Controllers
- 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
- DataSource and DataStream, the core concept for data read/processing/delivery