#1 Introduction Reuse templates and code
Reuse templates and code
This will show you how to place partial templates into separate files, and how to put functions you need in many places in separate files as well. It focuses on:
-
@Html.Partial(...)
to render another page (older versions of 2sxc used @RenderPage(...)
)
- see docs
-
DynamicModel
is the object used in sub-pages to receive parameters from the caller
- see docs
-
CreateInstance(...)
to create objects from .cs files
- see docs
-
Func<dynamic, dynamic>
micro-helpers are ideal for small sub-templates
- see docs
Reuse Shared Stuff Examples
- Micro-Helpers (like functions) with Template Delegates
- Reuse Razor Components with @Html.Partial and DynamicModel
- Reuse Razor Helpers (mini-templates) with CreateInstance
- Reuse a function library CreateInstance
- Reuse code with .cs files
CreateInstance is enhanced in 2sxc 10.01 to support .cs files to share code across Razor files and WebApi Controllers.
Deprecated Features
This shows / documents features which work, but are not recommended any more:
- Split Razor Templates into C#-Code and Template deprecated, Dnn Only
Now you can split out complicated C# code so designers don't have to worry about it.