Razor Components / Templates
Razor Templates will generate HTML - often based on the data a editor entered, and/or which was provided from the App.
Here's an example:
@inherits Custom.Hybrid.Razor12
<ul>
@foreach(var person in AsList(App.Data["Persons"])) {
<li>@person.Name</li>
}
</ul>
Razor Components/Templates are the most powerful templates in 2sxc since you can program anything you want using C#.
They use the Asp.Net Razor engine and contain normal HTML intermixed with Razor placeholders like @Content.FirstName
or longer code blocks usually marked with @{ ...}
.
The template files usually reside inside App root folder or sub folder. These always begin with an _
and end with .cshtml
.
Note
The View Configuration determines which razor file is being loaded.
If you are using Polymorphism then you may have multiple razor files with the same name in various folders, and Polymorph will decide which one will be shown.
Get Started with Razor Templates
We have an rich series of Razor tutorials. You should really check them out 👍.
- Install some Apps from the App Catalog - almost all apps use Razor
- Learn the APIs using
- The Razor Tutorials
- using these docs
- The technical RazorComponent API
- We also suggest you look into the RazorBlade library which has a lot of neat helpers
Read also
Tips
Tip
To use the latest features of 2sxc 12+, make sure your razor file begins with the line
@inherits Custom.Hybrid.Razor12
Otherwise your Razor templates is based on the default, older component code.
History
- Introduced in 2sxc 1.0