Skip to main content

Posts

Showing posts from November, 2017

Using Umbraco ModelsBuilder

Firstly, make sure the following properties are set in your solution's top-level web.config to enable the models builder:

<add key="Umbraco.ModelsBuilder.Enable" value="true"/>
<add key="Umbraco.ModelsBuilder.ModelsMode" value="LiveAppData"/>

I like the "LiveAppData" mode, but you should experiment with the others from the list in the ModelsBuilder docs here.  Generate your model classes, and include them in the VS Solution.
Unless you're on a brand new project, any existing views will need to be modified.

Model class inheritance Change instances of
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
to
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.ModelName>

Property Access Change instances of @Umbraco.Field("propertyAlias") to @Model.PropertyAlias Note that the ModelsBuilder converts property aliases to PascalCase instead of camelCase
Rendering Grid HTML Change instances of
@CurrentPage.GetGrid…