Copied to clipboard

Flag this post as spam?

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


  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Oct 30, 2014 @ 09:56
    Søren Kottal
    0

    Using Umbraco.Media in grid editor views (slimsy)

    How can I use Umbraco.Media for getting ie. ImageGetResponsiveUrl in the standard media.cshtml View in the new grid editor?

     

    I get an error, if I just paste the code from http://our.umbraco.org/projects/website-utilities/slimsy.

     

    This is probably simple for someone into Razor/C# :)

     

    media.cshtml is looking like this:

     

    @model dynamic
    @using Umbraco.Web.Templates
    @if (Model.value != null)
    {
    <div class="thumbnail">
            <img src="http://mce_host/forum/templating/templates-and-document-types/@Model.value.image" alt="@Model.value.caption" />
        </div>
    if (Model.value.caption != null)
        {
    <p class="caption">@Model.value.caption</p>
    }
    }
    

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 30, 2014 @ 10:45
    Jeavon Leopold
    102

    At the moment I would do this (I think Grid needs a strongly typed model, but that's not available yet):

    @inherits UmbracoViewPage<dynamic>
    @{    
        int nodeId;
        var res = int.TryParse(Model.value.id.ToString(), out nodeId);
    }
    @if (res && Model.value != null)
    {
        var typedMedia = Umbraco.TypedMedia(nodeId);
    
        <div class="thumbnail">
            <img src="@typedMedia.GetCropUrl()" alt="@Model.value.caption">
        </div>
        if (Model.value.caption != null)
        {
            <p class="caption">@Model.value.caption</p>
        }
    }
    
  • Hussein Khraibani 15 posts 98 karma points
    Mar 11, 2019 @ 12:29
    Hussein Khraibani
    0

    How would you do it in slimsy version 2?

    Thanks Jeavon

  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Oct 30, 2014 @ 11:25
    Søren Kottal
    0

    Great!

     

    Thanks, Jeavon

  • 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