Copied to clipboard

Flag this post as spam?

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


  • ianhoughton 233 posts 428 karma points c-trib
    Apr 12, 2012 @ 09:53
    ianhoughton
    0

    @Model.HasValue recursive ?

    I have the following code that works well until you move away from the page that holds the values (Home). I've converted the values to be recursive but am struggling to get the @Model.HasValue part to work:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
        if (@Model.showDonationBox == true)
        {
    
            double donationCurrent;
            donationCurrent = @Model.HasValue("_donationCurrent") ? @Model._donationCurrent : 1;
    
            double donationTarget = @Model._donationTarget;
            double progress = Math.Round((donationCurrent / donationTarget) * 100.00, 0);
            var progressWidth = @progress + "%;";
            <div class="widget">
                <h4 class="headng backcolr">@Model._donationTitle</h4>
                <div class="donation">
                    <p>@Model._donationText</p>
    
                    <!-- Need to convert this If statement to look up the tree to find the donationCurrent value, and if not found then not show the progressContainer -->
                    @if (@Model.HasValue("donationCurrent"))
                    {
                        <div id="progressContainer">
                        <div id="progress_bar" class="ui-progress-bar ui-container">
                            <div class="ui-progress" style="width: @progressWidth">
                                <span class="ui-label" style="display:none;">Processing <b class="value">79%</b></span>
                            </div><!-- .ui-progress -->
                        </div><!-- #progress_bar -->
                    </div>
                    }
    
                    <div class="collection">
                        <h2 class="colr bold">£@Model._donationCurrent</h2>
                        <h4 class="target bold">Target: £@Model._donationTarget</h4>
                    </div>
                    <h2 class="bold backcolr donbtn">
                        <a href="#">Donate Now</a></h2>
                </div>
            </div>
        }
    }

    Obviously @Model.HasValue("donationCurrent") works if your on the homepage where the value is stored, but if you move further down the tree, then it stops working.

  • ianhoughton 233 posts 428 karma points c-trib
    Apr 12, 2012 @ 09:58
    ianhoughton
    0

    Doh !! Try Googling a little longer !!

    @Model.HasValue("donationCurrent",true)
    

     

  • Greg McMullen 49 posts 195 karma points
    Nov 06, 2012 @ 21:59
    Greg McMullen
    0

    Thanks for the direction!

    I've also been misreading the _propertyAlias (recursive) element on the cheat sheet (stupid brain). Even though I've been able to get OTHER things to work correctly. 

  • Claushingebjerg 844 posts 2220 karma points
    Apr 17, 2019 @ 10:20
    Claushingebjerg
    0

    Has this changed in 8?

    doing

    @if(Model.HasValue("facebook",true)){ 
    -- some stuff -- 
    }
    

    returns this error: CS1503: Argument 3: cannot convert from 'bool' to 'string'

Please Sign in or register to post replies

Write your reply to:

Draft