Copied to clipboard

Flag this post as spam?

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


  • Craig100 1136 posts 2523 karma points c-trib
    Aug 24, 2016 @ 21:08
    Craig100
    0

    Access own docType fields in one Model when using another Model

    Have made a couple of additions to the Articulate docType. I can't seem to access them in the Articulate master I think because it uses Articulate.IMasterModel as it's model.

    @using ClientDependency.Core.Mvc
    @using Articulate;
    @model Articulate.Models.IMasterModel
    

    The ModelsBuilder put my new fields in Umbraco.Web.PublishedContentModels. If I put an @using Umbraco.Web.PublishedContentModels then I'm told that Articulate exists in two places Umbraco.Web.PublishedContentModels and my project DLL.

    @using ClientDependency.Core.Mvc
    @using Umbraco.Web.PublishedContentModels
    @model Articulate.Models.IMasterModel
    

    Is it possible to reference both or is there some other way to access extra docType fields that aren't in the compiled Articulate.IMasterModel interface? It's really confusing.

    Thanks.

    Craig

  • David Peck 687 posts 1863 karma points c-trib
    Aug 25, 2016 @ 11:09
    David Peck
    0

    I think Model.GetPropertyValue("") should still work, so you could not reference the PublishedContentModels. Alternatively you could create your own poco as a model (that implements IMasterModel).

    Finally you might want to exclude the articulate stuff from the model builder https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/ModelsGenerationConfiguration

  • Craig100 1136 posts 2523 karma points c-trib
    Aug 25, 2016 @ 13:48
    Craig100
    0

    Thanks David,

    As with most of the ModelsBuilder documentation it's totally opaque to me. It possibly means something to a C# MVC ninja. It's just not clear enough as to how you implement it.

    So I switched off ModelsBuilder and deleted the App_Data/Models folder and restarted the app. Added a simple bit of code to the Articulate master:-

    var pageTitle = string.IsNullOrWhiteSpace(Model.GetPropertyValue("metaTitle").ToString())
    

    And get the expected YSOD: Object reference not set to an instance of an object.

    Remember, at the top of the Articulate Master file is:-

    @using ClientDependency.Core.Mvc
    @using Articulate;
    @model Articulate.Models.IMasterModel
    

    Which means "Model" now refers to the compiled Articulate model which knows nothing about my alterations to it's docType.

    If I switch on ModelsBuilder, a new Articulate model is built in Umbraco.Web.PublishedContentModels and so we have a conflict.

    I always seem to get the sticky end when trying new Umbraco stuff. It costs A LOT of time and money to just then abandon it. I really wish documentation was available with some guidance for the non-ninjas amongst us. One day maybe.......

Please Sign in or register to post replies

Write your reply to:

Draft