AsList(...) - Magic Lists
In razor you prefer a simple @Something.Property
syntax. If you only have one item, you'll use AsDynamic(...). When you need a list to go through, you use AsList(...)
.
⚡ The official API docs.
Discover More in the Razor Tutorials
We have an rich series of Razor tutorials. You should really check them out 👍.
How it works
AsList has various signatures accepting a variety of input values. It then returns an IEnumerable<dynamic>
object which is a List
of IDynamicEntity objects. These are the things AsList can process:
- a
List<IEntity>
orIEnumerable<IEntity>
- will return a List/IEnumerable of IDynamicEntity - a
List<DynamicEntity>
orIEnumerable<IDynamicEntity>
- will return the same thing again
this option exists just so you don't have to pre-check what you pass in, making it easier to code for you - a IDataStream - will return a List/IEnumerable of IDynamicEntity
- a IDataSource - will return a List/IEnumerable of IDynamicEntity of the
"Default"
stream - a
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 10.20