Copied to clipboard

Flag this post as spam?

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


  • Annfinn Thomsen 24 posts 84 karma points
    May 14, 2014 @ 23:05
    Annfinn Thomsen
    0

    Converting to MVC

    Hello,

    is anyone able to translate this snippet to MVC / PartialView?

    @if (Model.Ancestors().Any())
    { 
        var imageNode = Library.NodeById(@Parameter.imageId);
        <img src="@imageNode.image" />
    }
    

    This is a snippet for a document type where I pick an image for an article. The issue right now is that the document property currently is an "upload", but I want it to be a "media picker".

    I positive that I need to use Umbraco.Media, but being too new to MVC, I'm stuck. :/

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 14, 2014 @ 23:27
    Jeavon Leopold
    0

    Hi Annfinn,

    Is this to be a Partial View Macro for the Parameter?

    Jeavon

  • Annfinn Thomsen 24 posts 84 karma points
    May 14, 2014 @ 23:32
    Annfinn Thomsen
    0

    Yes it is. Hello again, btw :) hehe

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 14, 2014 @ 23:39
    Jeavon Leopold
    0

    Hello! :-) I think this should do it:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @if (CurrentPage.Ancestors().Any())
    {
        if (Model.MacroParameters["imageId"] != null)
        {
            var imageNode = Umbraco.Media(Model.MacroParameters["imageId"]);
            <img src="@imageNode.image" />
        }
    }
    

    I'm not sure about the "image" property, is that your "Upload" property alias?

  • Annfinn Thomsen 24 posts 84 karma points
    May 15, 2014 @ 00:49
    Annfinn Thomsen
    0

    Hello,

    Thanks alot. Yes, the "image" is the alias for the "Upload" property. I'll just reuse it with "Media Picker".

    I oversaw one snippet, which is also in the legacy scripting language.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    
    @* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
    @if (Model.Children.Where("Visible").Any())
    {
    
    <div class="article_images">
    
        @* For each child page under the root node, where the property umbracoNaviHide is not True *@
        @foreach (var childPage in Model.Children.Where("Visible"))
        {
        <a href="@childPage.image" class="article_image" rel="shadowbox[gallery]">
        <img src="/[email protected]&amp;width=100" style="border: 0;" /></a>
        }
        </div>
    }
    

    What that snippet does, is to take all the published images added under the article node and show them.

    I tried converting the code, but I'm getting an runetime error. Here's is the code I tried:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @if (CurrentPage.Children.Where("Visible").Any())
    {
        <div class="article_images">
    
            @foreach (var childpage in CurrentPage.Children.Where("Visible"))
            { 
                <a href="@childPage.image" class="article_image" rel="shadowbox[gallery]">
                <img src="/[email protected]&amp;width=100" style="border: 0;" />
                </a>
            }
            </div>
    
    }
    

    To get the idea, you can visit http://www.fiskimannafelag.fo/savn/tidindi/skiparin-ov-litid-at-siga.aspx and scroll all the way down to the 3 pictures. The snippet make those 3 pictures appear. :)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 15, 2014 @ 10:55
    Jeavon Leopold
    0

    I think your only issue is that you have "childpage" and "childPage"

Please Sign in or register to post replies

Write your reply to:

Draft