Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul McCarthy 39 posts 160 karma points
    Feb 18, 2021 @ 18:16
    Paul McCarthy
    0

    Models not allowing direct access to properties

    I'm upgrading a site from 7 to 8. In my V8 site, I have finally got it to compile up to a point at least, but am struggling now with the templating.

    Whereas on the v7 site I can access a property such as Model.Title directly, in V8 I can only get to it by Model.Value("title"). This is using the Embedded version of ModelsBuilder, compiling to App_Data:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using Umbraco.Core.Models.PublishedContent;
    @using ContentModels = Umbraco.Core.Models.PublishedContent;
    @using Umbraco.Web.PublishedModels;
    @using Umbraco.ModelsBuilder;
    
    @{
        Layout = "Master.cshtml";
    
        var IsChristmas = Model.Value("IsChristmas"); // this works
    var Is Christmas = Model.IsChristmas; // this doesn't work
    

    Would it be better to install the full Models Builder and compile to dll?

  • Paul McCarthy 39 posts 160 karma points
    Feb 19, 2021 @ 16:10
    Paul McCarthy
    0

    To answer my own question.

    Not sure if this is to do with the Embedded.ModelBuilder, or an issue with VS, but when I removed it and installed the full ModelsBuilder and ModelsBuilder.UI I am now able to add the Model to the UmbracoViewPage:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Homepage>
    

    and can now reference model properties directly

Please Sign in or register to post replies

Write your reply to:

Draft