In your Content Views you will often want to get data either from the current page or get content from the database
The Content property is a default parameter and passing into the page.
Getting Content Properties
In your IContentView's you can get data using the following methods (Property aliases are used, these can be found on the Content Type page under the name of the property you have added)
Get a content property
@(Content!.GetValue<string>("PropertyAlias"))
The GetValue<TypeHere> accepts from types. Each content property has an example how how to use this method to get the data and the type to use. See the link below
To get media or content from a picker , it's a bit different, you need to pass in an instance of Mediatr. If you haven't defined it in the _imports like I have, make sure you Inject and instance of it.
You can use the same pattern for getting almost any type of data. i.e.
awaitMediator.Send(newQueryUsersCommand { Options added here })awaitMediator.Send(newQueryRolesCommand { Options added here })awaitMediator.Send(newQueryMediaCommand { Options added here })awaitMediator.Send(newQueryContentTypesCommand { Options added here })awaitMediator.Send(newQueryAuditsCommand { Options added here })awaitMediator.Send(newQueryLanguageCommand { Options added here })awaitMediator.Send(newQueryDomainCommand { Options added here })
Get Command
The Get*Command pattern returns a single item. For example the code below, returns a single content item by ID and includes all child content items
var page =awaitMediator.Send(newGetContentCommand{ Id =content.Id, IncludeChildren =true});
Again, you use the same pattern for all other data
awaitMediator.Send(newGetUserCommand { Options added here })awaitMediator.Send(newGetRoleCommand { Options added here })awaitMediator.Send(newGetMediaCommand { Options added here })awaitMediator.Send(newGetContentTypeCommand { Options added here })awaitMediator.Send(newGetDomainCommand { Options added here })awaitMediator.Send(newGetGlobalDataCommand { Options added here })awaitMediator.Send(newGetGlobalLanguageCommand { Options added here })
Save Command
If you want to programmatically save some content or media, we have a similar pattern for that too. They all follow the Save*Command i.e. SaveContentCommand, SaveMediaCommand etc...
var saveResult =awaitMediator.Send(newSaveContentCommand{ Content = ContentToSave});
All Save*Commands return a HandlerResult, which had a Success bool and also messages which contain error, information and warning messages