Copied to clipboard

Flag this post as spam?

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


  • Meni 273 posts 530 karma points
    Jan 29, 2023 @ 07:59
    Meni
    0

    Get CurrentPage in Partial View Macro Files Umbraco 11

    Hi, In my Umbraco 7.15.7 I'm getting the Current page in Partial View Macro Files as follow:

    @{
    if(CurrentPage.HasValue("articleImg")){      
        string w = (string)Umbraco.Media(CurrentPage.articleImg.ToString()).umbracoWidth;   
        string h = (string)Umbraco.Media(CurrentPage.articleImg.ToString()).umbracoHeight;
    

    So in Umbraco 11 I tried as following:

    @{
    if(Model.HasValue("articleImg")){        
        string w = (string)Umbraco.Media(Model.articleImg.ToString()).umbracoWidth; 
        string h = (string)Umbraco.Media(Model.articleImg.ToString()).umbracoHeight;
    

    (Model instead of CurrentPage)

    But I'm getting this error:

    'PartialViewMacroModel' does not contain a definition for 'HasValue' and the best extension method overload 'PublishedElementExtensions.HasValue(IPublishedElement, string, string?, string?)' requires a receiver of type 'IPublishedElement'
     if(Model.HasValue("articleImg")){
    

    Any idea?

    Thanks

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Jan 29, 2023 @ 09:16
    Huw Reddick
    100

    Hi Meni,

    You need to use Model.Content.HasValue("articleImg")

  • Meni 273 posts 530 karma points
    Jan 29, 2023 @ 20:07
    Meni
    0

    Thanks. works.

Please Sign in or register to post replies

Write your reply to:

Draft