Table of Contents

Razor Components / Templates

Razor Templates will generate HTML - often based on the data a editor entered, and/or which was provided from the App.

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

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

Discover More in the Razor Tutorials

We have an rich series of Razor tutorials. You should really check them out 👍.


  1. Install some Apps from the App Catalog - almost all apps use Razor
  2. Learn the APIs using
    1. The Razor Tutorials
    2. using these docs
    3. The technical RazorComponent API
  3. 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

  1. Introduced in 2sxc 1.0