Dynamic Code API
Every C# file in 2sxc is Dynamic Code as it's compiled on-the-fly and has a lot of helpers to work with Dynamic Data.
The following APIs are available on all 2sxc Dynamic Code. You can use this in:
- Razor
- WebAPI Controllers
- Helper Code files
Discover More in the Razor Tutorials
We have an rich series of Razor tutorials. You should really check them out 👍.
Instance Data in Dynamic Code
Note
Instance specific data belongs to the module-instance on the page, either because it was added manually as Content or because the View of the module-instance uses a Query.
Best read about App vs. Instance Data and Where Data Comes From
- Content
The primary and often the only content-items for this template. - Content.Presentation
Can contain additional presentation settings for this content, like how to format it. - Data
One or more Streams (lists) of zero-or-more content items - Header
The header data if the template expects to be a list and also needs a title or intro. - Header.Presentation
Can contain additional presentation settings for the header, like how to format it.
App and App-Data Objects
- App
The current App withSettings
,Resources
,Path
information and more. - App.Data
All the data of the current app for immediate use, fully cached in memory of the web server. - App.Query
Queries which were created using VisualQuery and can be run to access prepared data.
General Objects
- CmsContext
Information about the system, page, module etc. - Dnn
The common Dnn object providing page, module, user information - Edit
Helper providing you with various edit-functionality likeToolbar(...)
- Link
Helper to generate links, according to the Dnn-environment configuration
Conversion Commands
- AsAdam(...)
Gives you the ADAM parts (files, images, folders) of a field. - AsDynamic(entity) - takes just about anything (an iEntity, a list of iEntities, a dynamic, ...) and casts it to a DynamicEntity
- AsDynamic(jsonString)
- AsList(listOfEntities)
- AsEntity(...) - takes just about anything (iEntity, DynamicEntity, list of that) and casts it to an iEntity
Helper Commands provided by 2sxc
- CreateInstance(...)
To create an object of a parsed CSHTML file, for example to then access methods of that code - CreateSource<T>()
Get a DataSource object of typeT
(like filters, sorting, etc.) - GetService<T>() Get a Service to help you (using Dependency Injection)
Important Notes
Important
Your code must inherit the correct base class to get this API. You'll find the correct base classes in the documentations for Razor and Web API.