Copied to clipboard

Flag this post as spam?

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


  • Meni 281 posts 539 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 1932 posts 6722 karma points MVP 3x c-trib
    Jan 29, 2023 @ 09:16
    Huw Reddick
    100

    Hi Meni,

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

  • Meni 281 posts 539 karma points
    Jan 29, 2023 @ 20:07
    Meni
    0

    Thanks. works.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies