Model-bound views
If you integrated your app before , it's using the legacy ASP.NET Core Rendering SDK, version 22 or earlier. This SDK is no longer receiving updates, so we recommend that you upgrade to the latest version of the new .
Model-bound views use the default SitecoreComponentViewComponent view component, so you do not need to create a view component class.
When you have created your Razor view in the /Views/Shared/Components/SitecoreComponent folder and your view model class, you must map the Layout Service response to the view component with the AddModelBoundView<TModel>() extension method.
In the following example:
-
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 Sitecore content from model-bound view component Razor views
The Razor view of a model-bound view component uses a strongly-typed model that binds to properties in the Layout Service response.
The Razor view:
The ContentBlock model accessed in the Razor view: