Copied to clipboard

Flag this post as spam?

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


  • bh 226 posts 808 karma points
    Sep 05, 2019 @ 18:23
    bh
    0

    ModelsBuilder Dll Mode @Model.PropertyNameHere Fail

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Home>
    @using ContentModels = Umbraco.Web.PublishedModels;
    

    ...

    @Model.homeHeroImage.GetCropUrl(cropAlias: "1600x900")
    

    Error: Model does not contain a definition for homeHeroImage...

    I've published my models from models builder tab under settings 3 times. My project is targeting 4.7.2 I have the umbraco.web.dll project in my bin. What am I missing? The above worked like a champ in a previous project. Not sure what I'm missing.

    Since posting I've figured out that this works:

    Model.Value<IPublishedContent>("homeHeroImage").GetCropUrl(cropAlias: "1600x900")
    

    ...but why not

    @Model.homeHeroImage...
    

    ?

  • Magnus Eriksson 121 posts 361 karma points
    Sep 05, 2019 @ 19:40
    Magnus Eriksson
    0

    I would probably switch to AppData mode since it would then be easier to look at the generated models...?

    Regards, Magnus

  • Stephen 767 posts 2264 karma points c-trib
    Sep 06, 2019 @ 08:30
    Stephen
    0

    What mode are you using? Is it PureLive?

    What tool are you using to edit your views? Is it Visual Studio with Intellisense, or the Umbraco backoffice, or something else?

    From your code, I understand that the property alias is homeHeroImage. Now, Models Builder generates property names that sort of respect the C# coding style. Therefore, the property is quite possibly named HomeHeroImage with a capital H.

    Can you try that?

  • bh 226 posts 808 karma points
    Sep 06, 2019 @ 12:32
    bh
    1

    @Stephen I'm using Dll mode in VS 2019.

    Oddly, I closed VS down yesterday at the end of my work day. Opened it this morning and the Model.HomeHeroImage is showing up in intellisense.

    Thanks for your reply!!

  • bh 226 posts 808 karma points
    Sep 06, 2019 @ 13:52
    bh
    0

    Having the exact same issue today. Add a property to an existing DocType, Generate Models, and cannot use @Model.PropertyAlias Surely, I don't have to close and reopen VS 2019 every time I add a new property to a DocType. What am I missing?

  • Magnus Eriksson 121 posts 361 karma points
    Sep 06, 2019 @ 13:57
    Magnus Eriksson
    0

    Maybe Visual Studio doesn't notice the DLL being updated?

    But since you're using Visual Studio, why not use API or AppData/LiveAppData mode?

    Regards, Magnus

  • Stephen 767 posts 2264 karma points c-trib
    Sep 06, 2019 @ 14:25
    Stephen
    0

    No idea why VS would not pick changes in the DLL when it's re-generated. Will try to reproduce. But yes, if you are using VS, it would be simpler to use the API / extension.

  • bh 226 posts 808 karma points
    Sep 06, 2019 @ 15:34
    bh
    0

    Alright, I'm going to try the API/extension route. But, I'm getting this error "cannot find custom tool UmbracoModelsBuilder on this system" when I do these steps.

    enter image description here

  • Stephen 767 posts 2264 karma points c-trib
    Sep 06, 2019 @ 16:53
    Stephen
    101

    The custom tool is deprecated in favor of the extension. See this blog post: https://www.zpqrtbnk.net/posts/models-builder-extension/

    Well get there ;)

  • bh 226 posts 808 karma points
    Sep 06, 2019 @ 18:02
    bh
    0

    @Stephen...thank you sir! I was using the extension with the Custom Tool documentation. Thanks for pointing me to the extension documentation. You're the man!

Please Sign in or register to post replies

Write your reply to:

Draft