Model-bound views
Model-bound views use the default Sitecore view component named SitecoreComponentViewComponent. This means that you don't need to create a view component class.
Build a model-bound view
To build a model-bound view:
-
Create your Razor view in the
/Views/Shared/Components/SitecoreComponentfolder. -
Create your view model class.
-
Map the Experience Edge response to the view component with the
AddModelBoundView<TModel>()extension method.
Example
Here's an example model-bound view. Note the following:
-
AddModelBoundView<BoundContentBlock>("ContentBlock")maps theContentBlockresponse component to the defaultSitecoreComponentViewComponentview component; uses theContentBlock.cshtmlview; and provides the view with theBoundContentBlockmodel. -
AddModelBoundView<BoundGenericBlock>(name => name.StartsWith("sc"), "GenericBlock")maps all response components prefixed withscto theGenericBlockViewComponentview component; uses theGenericBlock.cshtmlview; and provides the view with theBoundGenericBlockmodel.
Accessing SitecoreAI content from Razor views
The Razor view of a model-bound view uses a strongly-typed model that binds to properties in the Experience Edge response.
Here's an example Razor view:
Here's an example ContentBlock model accessed in the Razor view: