Copied to clipboard

Flag this post as spam?

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


  • Mads Sørensen 188 posts 433 karma points
    Sep 16, 2014 @ 09:37
    Mads Sørensen
    0

    PartialView: Change variable value

    Hi Guys 
    I got at problem with changing value in my var my code looks like this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Eksponent.CropUp
    
    @foreach(var focusBox in Model.Content.AncestorOrSelf(1).Descendants("FokusBoxRight")) 
    {
        var mediaItem = Umbraco.TypedMedia(focusBox.GetPropertyValue("baggrundsbillede"));
    
        <div class="focusBox" style="background: #000 url(@mediaItem.GetPropertyValue("umbracoFile")) no-repeat left top; color: white;">
    
    
            @focusBox.GetPropertyValue("tekst")
    
            @{
                var link = "#";
                var linkTarget = "_self";
    
                if (focusBox.HasValue("interntLink")) 
                {
                    link = Umbraco.NiceUrl(focusBox.interntLink);
                }
    
                else if(focusBox.HasValue("eksterntLink"))
                {
                    link = focusBox.eksterntLink;
                }
    
                else if(focusBox.HasValue("mediaLink"))
                {
                    link = Umbraco.Media(focusBox.mediaLink).Url;
                }
    
                if (focusBox.Where("nytVindue = '1'"))
                {
                    linkTarget = "_blank";
                }
    
             }
    
    
    
            <a href="@link" target="@linkTarget">Læs mere</a>
    
        </div>
    }

     

    The error sounds like: CS1061: 'Umbraco.Core.Models.IPublishedContent' dosent contain a definition of 'interntLink.

    Can someone please help me :P

  • Peter Nielsen 159 posts 257 karma points
    Sep 16, 2014 @ 09:47
    Peter Nielsen
    0

    Try using:

    link = Umbraco.NiceUrl(focusBox.GetPropertyValue("interntLink"));
    

    instead :-)

  • Mads Sørensen 188 posts 433 karma points
    Sep 16, 2014 @ 09:52
    Mads Sørensen
    0

    Already tried that it jyst gives me an other error:
    contains invalid arguments :P 

  • Peter Nielsen 159 posts 257 karma points
    Sep 16, 2014 @ 10:08
    Peter Nielsen
    0

    It could be the NiceUrl that is returning that one.

    Try this for debugging:

    link = focusBox.GetPropertyValue("interntLink");
    
  • Mads Sørensen 188 posts 433 karma points
    Sep 16, 2014 @ 10:11
    Mads Sørensen
    0

    Well, have also been there, and it also gives me an error:

    The type 'object' can not be converted implicitly to 'string'

    I'm really confused because - im pretty sure this have worked for me before :/ 

  • Peter Nielsen 159 posts 257 karma points
    Sep 16, 2014 @ 10:14
    Peter Nielsen
    1

    Try:

    link = focusBox.GetPropertyValue("interntLink").ToString();
    
  • Mads Sørensen 188 posts 433 karma points
    Sep 16, 2014 @ 10:26
    Mads Sørensen
    0

    Ahh okay, but what should i do to the node ID i got then?

  • Peter Nielsen 159 posts 257 karma points
    Sep 16, 2014 @ 10:30
    Peter Nielsen
    0

    Try and check if it insert a node ID, or if it is missing somewhere. If there is one that is empty i could indicate that the HasValue() doesn't work.

    Then you maybe could do something like this instead:

    if (focusBox.HasValue("interntLink") && focusBox.GetPropertyValue("interntLink") != null && focusBox.GetPropertyValue("interntLink").ToString() != "") 
        {
            link = Umbraco.NiceUrl(int.Parse(focusBox.GetPropertyValue("interntLink").ToString()));
        }
    
  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Sep 16, 2014 @ 10:30
    Jeavon Leopold
    1

    NiceUrl parameter must be a int, so it should be like this

     link = Umbraco.NiceUrl(focusBox.GetPropertyValue<int>("interntLink"));
    
  • Mads Sørensen 188 posts 433 karma points
    Sep 16, 2014 @ 10:47
    Mads Sørensen
    1

    Hi Jeavon, worked perfect :D
    I finally got it to work :D

    Next time i'll post my Umbraco version as one of the first informations :D

    Final code for curious people looks like this:

    Umbraco version Umbraco v6.0.5

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Eksponent.CropUp
    
    @foreach(var focusBox in Model.Content.AncestorOrSelf(1).Descendants("FokusBoxRight")) 
    {
        var mediaItem = Umbraco.TypedMedia(focusBox.GetPropertyValue("baggrundsbillede"));
    
        <div class="focusBoxRight" style="background: #000 url(@mediaItem.GetPropertyValue("umbracoFile")) no-repeat left top;">
    
            @if(focusBox.HasValue("overskrift"))
            {
                <h1>@focusBox.GetPropertyValue("overskrift")</h1>
            }
    
    
            @focusBox.GetPropertyValue("tekst")
    
            @{
                var link = "#";
                var linkTarget = "_self";
    
                if (focusBox.HasValue("interntLink")) 
                {
                    link = Umbraco.NiceUrl(focusBox.GetPropertyValue<int>("interntLink")); 
                }
    
                else if(focusBox.HasValue("eksterntLink"))
                {
                    link = focusBox.GetPropertyValue("eksterntLink").ToString();
                }
    
                else if(focusBox.HasValue("mediaLink"))
                {
                    link = Umbraco.Media(focusBox.GetPropertyValue("mediaLink")).Url;
                }
    
                if (focusBox.Where("nytVindue = True"))
                {
                    linkTarget = "_blank";
                }
    
             }
    
            <a class="readMore" href="@link" target="@linkTarget"><span><img src="/images/rld/btn_arrow_white.png" /></span>Læs mere</a>
    
        </div>
    }

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Sep 16, 2014 @ 10:50
    Jeavon Leopold
    0

    Good stuff and yes always a good idea to start forum posts including your Umbraco version :)

    I would also use the type specifier here:

            else if(focusBox.HasValue("eksterntLink"))
            {
                link = focusBox.GetPropertyValue<string>("eksterntLink");
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft