Copied to clipboard

Flag this post as spam?

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


  • Aung Zin Phyo 17 posts 87 karma points
    Jan 08, 2020 @ 09:03
    Aung Zin Phyo
    0

    Get Media Url in surface controller

           IContentService contentService = Services.ContentService;
    
            var content = contentService.GetById(1119);
            string aa = content.GetValue("CarRefName").ToString();
            string bb = content.GetValue("VehecleNo").ToString();
            var image = content.GetValue<IPublishedContent>("ChooseFeatureImage").Url;
    

    This is error.May I know how to get media url in surface controller.

  • Marc Goodson 2157 posts 14411 karma points MVP 9x c-trib
    Jan 08, 2020 @ 09:22
    Marc Goodson
    1

    Hi Aung

    In a SurfaceController you have access to the UmbracoHelper class via the 'Umbraco' property so the above could be:

            var content = Umbraco.Content(1119);
            if (content!=null){
                 string aa = content.Value<string>("CarRefName");
                 string bb = content.Value<string>("VehecleNo");
                 var image = content.Value<IPublishedContent>("ChooseFeatureImage");
                 var imageUrl = image!=null ? image.Url : "";
            }
    

    When you use the ContentService you are querying the database directly, using the UmbracoHelper you are querying the published Umbraco cache - which is much faster!

    regards

    Marc

  • Aung Zin Phyo 17 posts 87 karma points
    Jan 09, 2020 @ 11:50
    Aung Zin Phyo
    0

    How I use UmbracoHelper method.Please show me simple.

Please Sign in or register to post replies

Write your reply to:

Draft