App.Data / @App.Data Object in Dynamic Code
The App.Data
object gives you immediate acccess to all data in the app, through the Data
property. Basically you can use it as follows:
Get All Data Items of a Content Type
App.Data["ContentTypeName"]
will give you a stream of all entities of that type. In most cases you'll use an AsList(...)
to use it efficiently in loops etc. because most of the razor templating will prefer a DynamicEntity to a pure IEntity-object. Here's an example:
@foreach(var post in AsList(App.Data["BlogPost"]))
{
@Html.Partial("_list-item.cshtml", new { Post = post })
}
note: this will give you all items, but you'll have to sort it using LINQ or other mechanisms. If you're not familiar with that, you're better of using App.Query[...]
(see below).
Edit App Data Content-Items
In addition to giving access to all entities in this app, you can also create, edit and delete items using the App.Data
object. The commands provided are:
App.Data.Create(contentTypeName, values, userName)
App.Data.Update(entityId, values, userName)
App.Data.Delete(entityId, userName)
You can read more about this in the App Data API Feature
Create Metadata #todoc
Read Metadata #todoc
Demo App and further links #todoc
History
- Introduced in 2sxc 05.05
- Stable since 2sxc 06.00
- Data-API was introduced in 2sxc 06.05