Skip to main content

Learn Razor for Advanced, Funky Stuff

Razor is a standard Microsoft technology for templating HTML. Because of this, there i a LOT of information out in the web related to Razor that you can use. To use Razor with 2sxc, you should:

  1. Learn the basics of Razor - using simple 2sxc samples and examples / tutorials from around the web
  2. Learn what 2sxc adds to Razor - to leverage that as well
  3. Learn the best ways to solve common issues (not documented yet, todo)
  4. Learn related technologies like LINQ to build on that (not documented yet, todo)

Step 1: Learn Razor Basics

You want to understand the very basics of Razor. To do this, I recommend you start with

  1. The two tutorial videos you'll see below
  2. Some external learning materials for more infos - linked after the videos
  3. Various Apps containing lots of code examples - also linked after the videos

First Steps with Razor

As easy as tokens and much more powerfull. You really want to get into Razor :)

See results here

Razor Lists

Using Razor to render lists is almost as easy as with Tokens, but opens a universe of possibilities.

See results here

> Details

> Details

Official Introduction to Razor

This is the official introduction from - probably the best place to get started. It's very comprehensive and long - so has just about everything you need to know (and much more). I recommend reading the first 5-10 pages, then come back here. 

> Details

> Details

Razor course/introduction by

This is a simple getting into-razor info. They also have additional infos like C# variables etc. 

> Details

> Details

Apps to learn Razor

This shows you the apps in the catalog using Razor. Some are pure demo-apps, others are real-life apps with advanced features. 

Step 2: Learn What 2sxc/DNN adds to Razor

I'm not done writing about this yet, but I'll try to just give you a quick summary:

  1. 2sxc usually takes care of getting Content or Data for your Template or View. So in general, you do not have to write any code to get content/data, it's just there. So there are at least x ways to get Content/Data
    1. In the basic data-objects like @Content or @ListContent - you'll see many code-samples using this
    2. From the @Data object which contains lists of content-items which were delivered to this template (MVC-Style). So Data["Default"] contains the main Stream of data, but together with the Visual-Query-Designer you can have many more streams. This is the preferred method for most data-lists and also works for SQL, CSV, FnL data etc. 
    3. The @App.Data object is the global data-object for this App, giving you code-access to all Content-Items in this App
    4. Using custom C# code to get data in the Intialize-section of your template - like for SQL or other data.
  2. 2sxc gives you access to DNN material using the @Dnn Variable. It's identical to the standard Dnn Variable
  3. 2sxc also provides additional helpers like AsDynamic, AsEntity and more. You'll see many such examples in the demo-apps and code samples. 


I'll try to write more about all this later on, but I think you'll find most of it intuitive if you check out some example Apps.

Relationships - Connecting Information

Here's how you can connect information - like articles and tags or courses and authors.

See results here