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 04, 2014 @ 01:03
    Annfinn Thomsen
    0

    Media Picker, image on page.

    Hello,

    The media picker property is called "mynd1". I created a partical view file.

    I've got the following code:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @if (Model != null)
        {
        var authorNode = Library.NodeById(Model.authorId);
            var articleImage = "css/images/dumy-article-small.gif";
            <div class="article_header">
                <div class="title">@Model.title</div>
                <div class="clear"></div>
            </div>
            <div class="second_header">
                <div class="author_name"><b>Eftir</b>: @authorNode.fullName</div>
                <div class="category_diplaydate">
                    <b>Bólkur</b>: <a href="@Model.Parent.Url">@Model.Parent.Name</a><br />
                    <b>Dagfesting</b>: @Model.articleDate.ToString("dddd, dd.MM.yyyy HH:mm")
                    <div class="print_icon"><a href="@umbraco.library.NiceUrl(2354)[email protected]" target="_blank"><img src="~/css/images/printer.png"  alt="#" />Prenta</a></div>
                </div>
            </div>
            <div class="clear"></div>
            <br/>   
                <div class="Manchet">@Model.manchet</div>
                <br/>
                <div>
                         @if (item.HasValue("mynd1"))
                           {
                             var dynamicMediaItem = Umbraco.Media(item.mynd1);
                             <a href="#">
                             <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/></a>
                           }
                </div>      
              <div class="Breydtekstur">@Model.bodyText</div>
                  <br/>
        }
    

    But I'm getting an runtime error when I try to enter the page. Is anyone able to help me out?

    I'm also using Umbraco 6.1.5

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 04, 2014 @ 01:24
    Jeavon Leopold
    0

    Hi Annfinn,

    It looks like you have created a legacy "Scripting File" instead of a MVC "Partial View" or "Macro Partial View".

    Your snippet should be something like this (make sure it's saved with the Views/Partials or Views/MacroPartials folder)

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
        @{
        var authorNode = Umbraco.Content(CurrentPage.authorId);
            var articleImage = "css/images/dumy-article-small.gif";
            <div class="article_header">
                <div class="title">@CurrentPage.title</div>
                <div class="clear"></div>
            </div>
            <div class="second_header">
                <div class="author_name"><b>Eftir</b>: @authorNode.fullName</div>
                <div class="category_diplaydate">
                    <b>Bólkur</b>: <a href="@CurrentPage.Parent.Url">@CurrentPage.Parent.Name</a><br />
                    <b>Dagfesting</b>: @CurrentPage.articleDate.ToString("dddd, dd.MM.yyyy HH:mm")
                    <div class="print_icon"><a href="@Umbraco.NiceUrl(2354)[email protected]" target="_blank"><img src="~/css/images/printer.png"  alt="#" />Prenta</a></div>
                </div>
            </div>
            <div class="clear"></div>
            <br/>   
                <div class="Manchet">@CurrentPage.manchet</div>
                <br/>
                <div>
                    @{
    
                        var item = SOMETHING?????;
    
                        if (item.HasValue("mynd1"))
                        {
                            var dynamicMediaItem = Umbraco.Media(item.mynd1);
                            <a href="#">
                                <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/></a>
                        }
                    }
                </div>      
              <div class="Breydtekstur">@CurrentPage.bodyText</div>
                  <br/>
        }
    

    How are you calling your Partial View from your View?

    Make sure you check the MVC documentation here.

    Jeavon

  • Annfinn Thomsen 24 posts 84 karma points
    May 04, 2014 @ 15:07
    Annfinn Thomsen
    0

    Hello

    thanks for taking time to answer my question. I'm in very early stages of programming. :(

    The above code works, with out the

    @{
             var item = test;
                if (item.HasValue("mynd1"))
                    {
                        var dynamicMediaItem = Umbraco.Media(item.mynd1);
                        <a href="#">
                         <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/></a>
                    }
                }
    

    But as soon as I put in that codesnippet, I get runtime error.

    I'm also using:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    instead of:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    Is that an error on my behalf? It I don't use the PartialViewMacroPage, I also get an runtime error.

    The Partial view is being called like this (hope it makes sense): CSHTML file -> Macro -> Template -> Document type.

    The CSHTML file is located in the "Partial View Macro files" folder.

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

    That's all fine, in not entirely sure what item is, but maybe try var item = CurrentPage; and see if thats what you're looking for?

  • Annfinn Thomsen 24 posts 84 karma points
    May 07, 2014 @ 17:10
    Annfinn Thomsen
    0

    I found the issues. The issues was that I was using too many @'s :)

Please Sign in or register to post replies

Write your reply to:

Draft