Copied to clipboard

Flag this post as spam?

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

  • Patrick Shaun McNicholas 2 posts 92 karma points
    Dec 22, 2018 @ 19:47
    Patrick Shaun McNicholas

    Access to Media Picker without using Model

    I've taken over management for a website built in Umbraco 7.6.3 and the company that built the system has utilized a traditional .Net MVC using the @Model object. Which means that much of the functionality native to Umbraco is lost.

    I need to be able to render images selected using the Media.Picker however the only place that I can find any documentation on accessing that object all require that I use the @Model in umbraco in order to resolve the Url of the selected image.

    I'm building the needed section of the pages using a Partial View

    Any suggestions would be very very useful to me??!!!

    @using Umbraco.Web;
    @using Umbraco.Web.Extensions;
    @using ClientDependency.Core.Mvc;
    var currentPageId =  UmbracoContext.Current.PageId;
    var currentUrl =  Umbraco.Url(Convert.ToInt32(UmbracoContext.Current.PageId));
    <!-- Open Graph Current Page: @currentPageId | Current Url: @Umbraco.UrlAbsolute(Convert.ToInt32(UmbracoContext.Current.PageId)) -->
    string oglocale = "en_US";
    string ogsite_name = "Some University";
    string ogtitle = Umbraco.Field("ogtitle", recursive: true).ToString();
    string ogurl = !String.IsNullOrEmpty(Umbraco.Field("ogurl", recursive: true).ToString()) ? Umbraco.Field("ogurl", recursive: true).ToString() : Umbraco.UrlAbsolute(Convert.ToInt32(UmbracoContext.Current.PageId)) ;
    string ogdescription = Umbraco.Field("ogdescription", recursive: true).ToString();
    string ogimage = Umbraco.Media(1143).umbracoFile.ToString();
    dynamic ogimageId = Umbraco.Field("ogimage", recursive: true);
    // string ogimageUrl = Umbraco.Media(ogimageId).Url;
    <!-- ogimageUrl: @ogimageId.ToString() -->
    string ogtype = Umbraco.Field("ogtype", recursive: true).ToString();
    string articleauthor = Umbraco.Field("articleauthor", recursive: true).ToString();
    string twittersite = Umbraco.Field("twittersite", recursive: true).ToString();
    string twittercreator = Umbraco.Field("twittercreator", recursive: true).ToString();
    string twittercard = Umbraco.Field("twittercard", recursive: true).ToString();
    string twittertitle = Umbraco.Field("twittertitle", recursive: true).ToString();
    string twitterdescription = Umbraco.Field("twitterdescription", recursive: true).ToString();
    string twitterimage = Umbraco.Media(1143).umbracoFile.ToString();; // Umbraco.Field("twitterimage", recursive: true).ToString();
    <meta property="og:locale" content="@oglocale" />
    <meta property="og:site_name" content="@ogsite_name" />
    <meta property="og:title" content="@ogtitle" />
    <meta property="og:url" content="@ogurl" />
    <meta property="og:description" content="@ogdescription" />
    <meta property="og:image" content="@ogimage" />
    <meta property="og:type" content="@ogtype" />
    <!-- articleauthor -->
    <!-- Twitter Cards -->
    <meta name="twitter:site" content="@twittersite" />
    <meta name="twitter:creator" content="@twittercreator" />
    <meta name="twitter:card" content="@twittercard" />
    <meta name="twitter:title" content="@twittertitle" />
    <meta name="twitter:description" content="@twitterdescription" />
    <meta name="twitter:image" content="@twitterimage" />
    <!-- End Meta Fields -->
  • Patrick Shaun McNicholas 2 posts 92 karma points
    Dec 30, 2018 @ 22:43
    Patrick Shaun McNicholas

    So I figured this out before anyone had a chance to respond... Here's the solution... didn't realize it would be so simple...

    string ogimageId = Html.Raw(Umbraco.Field("ogimage", recursive: true)).ToString();
    string ogimage = Umbraco.Media(ogimageId).umbracoFile.ToString();
Please Sign in or register to post replies

Write your reply to: