Copied to clipboard

Flag this post as spam?

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


  • Vuyo 4 posts 75 karma points
    Jun 08, 2021 @ 08:32
    Vuyo
    0

    Umbraco 8 - Collection returning nulls after code was modified for Umbraco 8 from Umbraco 7

    Hi,

    Could I please get some assistance with my code that previously worked on v7 and once I changed a few lines to be inline with v8, nothing is returned.

    Code:

    @{ var site = ""; if (Request.Cookies["site"] != null) { site = Request.Cookies["site"].Value; } else { site = "Main"; } Layout = null;

    System.Collections.Specialized.StringCollection layoutItems = new System.Collections.Specialized.StringCollection();
    //  var site = "";
    
    string buttonUrlGlobabl = "";
    if (site == "Power")
    {
        if (Model.Value("SiteType") != null && Model.Value("SiteType").ToString().Trim().Length > 0 && Model.Value("SiteType").ToString() == "Power")
        {
            if ((Model.Value("first") != null) && (Model.Value("first").ToString().Trim().Length > 0) && (!Model.Value("first").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
            {
                layoutItems.Add(Model.Value("first").ToString());
            }
    
            if ((Model.Value("second") != null) && (Model.Value("second").ToString().Trim().Length > 0) && (!Model.Value("second").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
            {
                layoutItems.Add(Model.Value("second").ToString());
            }
    
            if ((Model.Value("third") != null) && (Model.Value("third").ToString().Trim().Length > 0) && (!Model.Value("third").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
            {
                layoutItems.Add(Model.Value("third").ToString());
            }
    
            if ((Model.Value("fourth") != null) && (Model.Value("fourth").ToString().Trim().Length > 0) && (!Model.Value("fourth").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
            {
                layoutItems.Add(Model.Value("fourth").ToString());
            }
    
            if ((Model.Value("fifth") != null) && (Model.Value("fifth").ToString().Trim().Length > 0) && (!Model.Value("fifth").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
            {
                layoutItems.Add(Model.Value("fifth").ToString());
            }
    
            if ((Model.Value("sixth") != null) && (Model.Value("sixth").ToString().Trim().Length > 0) && (!Model.Value("sixth").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
            {
                layoutItems.Add(Model.Value("sixth").ToString());
            }
    
            if ((Model.Value("seventh") != null) && (Model.Value("seventh").ToString().Trim().Length > 0) && (!Model.Value("seventh").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
            {
                layoutItems.Add(Model.Value("seventh").ToString());
            }
    
            if ((Model.Value("eighth") != null) && (Model.Value("eighth").ToString().Trim().Length > 0) && (!Model.Value("eighth").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
            {
                layoutItems.Add(Model.Value("eighth").ToString());
            }
    
            string titleUrl = (Model.Value("titleExternalUrl") != null) ? Model.Value("titleExternalUrl").ToString() : string.Empty;
            string titleTarget = "_blank";
            bool titleScrollTo = false;
    
            if (string.IsNullOrEmpty(titleUrl))
            {
                if ((Model.Value("titleDownloadFile") != null) && (Model.Value("titleDownloadFile").ToString().Trim().Length > 0))
                {
                    titleUrl = Model.Value<IPublishedContent>("titleDownloadFile")?.Url ?? "";
                }
                else if ((Model.Value("titleInternalLink") != null) && (Model.Value("titleInternalLink").ToString().Trim().Length > 0))
                {
                    titleUrl = Model.Value<IPublishedContent>("titleInternalLink")?.Url ?? "";
                    titleTarget = "_self";
                }
                else if ((Model.Value("titleScrollTo") != null) && (Model.Value("titleScrollTo").ToString().Trim().Length > 0))
                {
                    titleUrl = "#content-item-" + Model.Value("titleScrollTo").ToString();
                    titleTarget = "_self";
                    titleScrollTo = true;
                }
            }
    
            foreach (string layoutItem in layoutItems)
            {
                int columnWidth = Convert.ToInt32(Model.Value("columnWidth"));
                int headerStartIndex = 4;
    
                if ((columnWidth >= 9) && (columnWidth <= 12))
                {
                    headerStartIndex = 2;
                }
                else if ((columnWidth >= 5) && (columnWidth <= 8))
                {
                    headerStartIndex = 3;
                }
    
                switch (layoutItem.ToLower())
                {
                    case "image":
                        {
                            var cropSelected = Model.Value("imageCropper");
                            var crop = (cropSelected != null && cropSelected.ToString().Trim().Length > 0) ? cropSelected.ToString() : "default";
                            string value = Model.GetCropUrl(crop, "image");
    
                            if (!string.IsNullOrEmpty(value))
                            {
                                <div class="image full-width text-left">
                                    @if (!string.IsNullOrEmpty(titleUrl))
                                    {
                                        @:<a href="@((titleScrollTo) ? titleUrl : titleUrl)" rel="noopener" target="@titleTarget" title="@Model.Value("title")" @Html.Raw((titleScrollTo) ? " class=\"scroll-to\"" : string.Empty)>
                                        }
    
                                    <img src="@value" alt="@Model.Value("title")" class="img-responsive" />
    
                                    @if (!string.IsNullOrEmpty(titleUrl))
                                    {
                                    @:</a>
                                }
                                </div>
                            }
    
                            break;
                        }
    
                    case "video":
                        {
    
                            string value = (Model.Value("video") != null) ? Model.Value("video").ToString() : string.Empty;
    
                            if (!string.IsNullOrEmpty(value))
                            {
                                value += ((value.IndexOf("?") > 0) ? "&" : "?") + "wmode=opaque";
    
                                <div class="video"><iframe src="@value" frameborder="0" width="560" height="315"></iframe></div>
                            }
    
                            break;
                        }
    
                    case "title":
                        {
                            string value = (Model.Value("title") != null) ? Model.Value("title").ToString() : string.Empty;
    
                            if (!string.IsNullOrEmpty(value))
                            {
                                string alignClass = ((Model.Value("titleAlign") != null) && (Model.Value("titleAlign").ToString().Trim().Length > 0) && (!Model.Value("titleAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("titleAlign").ToString().ToLower() : "left";
    
                                <div class="title text-@alignClass">
                                    @Html.Raw("<h" + headerStartIndex.ToString() + ">")
    
                                    @if (!string.IsNullOrEmpty(titleUrl))
                                    {
                                        @:<a href="@((titleScrollTo) ? titleUrl : titleUrl)" target="@titleTarget" rel="noopener" title="@value" @Html.Raw((titleScrollTo) ? " class=\"scroll-to\"" : string.Empty)>
                                        }
    
                                    @value
    
                                    @if (!string.IsNullOrEmpty(titleUrl))
                                    {
                                    @:</a>
                                }
    
                                    @Html.Raw("</h" + headerStartIndex.ToString() + ">")
                                </div>
                            }
    
                            break;
                        }
    
                    case "subtitle":
                        {
                            string value = (Model.Value("subtitle") != null) ? Model.Value("subtitle").ToString() : string.Empty;
    
                            if (!string.IsNullOrEmpty(value))
                            {
                                string alignClass = ((Model.Value("subtitleAlign") != null) && (Model.Value("subtitleAlign").ToString().Trim().Length > 0) && (!Model.Value("subtitleAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("subtitleAlign").ToString().ToLower() : "left";
    
                                <div class="sub-title text-@alignClass">
                                    @Html.Raw("<h" + (headerStartIndex + 1).ToString() + ">")
                                    @value
                                    @Html.Raw("</h" + (headerStartIndex + 1).ToString() + ">")
                                </div>
                            }
    
                            break;
                        }
    
                    case "description":
                        {
                            string value = (Model.Value("description") != null) ? Model.Value("description").ToString() : string.Empty;
    
                            if (!string.IsNullOrEmpty(value))
                            {
                                string alignClass = ((Model.Value("descriptionAlign") != null) && (Model.Value("descriptionAlign").ToString().Trim().Length > 0) && (!Model.Value("descriptionAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("descriptionAlign").ToString().ToLower() : "left";
    
                                <div class="description text-@alignClass">
                                    @Html.Raw("<h" + (headerStartIndex + 2).ToString() + ">")
                                    @value
                                    @Html.Raw("</h" + (headerStartIndex + 2).ToString() + ">")
                                </div>
                            }
    
                            break;
                        }
    
                    case "text":
                        {
                            string value = (Model.Value("text") != null) ? Model.Value("text").ToString() : string.Empty;
    
                            if (!string.IsNullOrEmpty(value))
                            {
                                string alignClass = ((Model.Value("textAlign") != null) && (Model.Value("textAlign").ToString().Trim().Length > 0) && (!Model.Value("textAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("textAlign").ToString().ToLower() : "left";
    
                                <div class="text text-@alignClass" @Html.Raw(((Model.Value("textMinimumHeight") != null) && (Model.Value("textMinimumHeight").ToString().Trim().Length > 0)) ? " style=\"min-height:" + Model.Value("textMinimumHeight").ToString() + "px;\"" : string.Empty)>@Html.Raw("Test")</div>
                            }
    
                            break;
                        }
    
                    case "button":
                        {
                            string buttonUrl = (Model.Value("buttonExternalUrl") != null) ? Model.Value("buttonExternalUrl").ToString() : string.Empty;
                            string buttonTarget = "_blank";
                            bool buttonScrollTo = false;
    
                            if (string.IsNullOrEmpty(buttonUrl))
                            {
                                if ((Model.Value("buttonDownloadFile") != null) && (Model.Value("buttonDownloadFile").ToString().Trim().Length > 0))
                                {
                                    buttonUrl = Model.Value<IPublishedContent>("buttonDownloadFile")?.Url ?? "";
                                }
                                else if ((Model.Value("buttonInternalLink") != null) && (Model.Value("buttonInternalLink").ToString().Trim().Length > 0))
                                {
                                    buttonUrl = Model.Value<IPublishedContent>("buttonInternalLink")?.Url ?? "";
                                    buttonTarget = "_self";
                                }
                                else if ((Model.Value("buttonScrollTo") != null) && (Model.Value("buttonScrollTo").ToString().Trim().Length > 0))
                                {
                                    buttonUrl = "#content-item-" + Model.Value("buttonScrollTo").ToString();
                                    buttonTarget = "_self";
                                    buttonScrollTo = true;
                                }
    
                            }
                            buttonUrlGlobabl = buttonUrl;
                            if (!string.IsNullOrEmpty(buttonUrl))
                            {
                                string alignClass = ((Model.Value("buttonAlign") != null) && (Model.Value("buttonAlign").ToString().Trim().Length > 0) && (!Model.Value("buttonAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("buttonAlign").ToString().ToLower() : "left";
    
                                <div id="button1" class="button clearfix text-@alignClass"><a href="@((buttonScrollTo) ? buttonUrl : buttonUrl)" title="" rel="noopener" class="btn btn-primary pull-@alignClass@((buttonScrollTo) ? " scroll-to" : string.Empty)">@Model.Value("buttonLabel")</a></div>
                            }
    
                            break;
                        }
    
                    case "button 2":
                        {
                            string buttonUrl = (Model.Value("button2ExternalUrl") != null) ? Model.Value("button2ExternalUrl").ToString() : string.Empty;
                            string buttonTarget = "_blank";
                            bool buttonScrollTo = false;
    
                            if (string.IsNullOrEmpty(buttonUrl))
                            {
                                if ((Model.Value("button2DownloadFile") != null) && (Model.Value("button2DownloadFile").ToString().Trim().Length > 0))
                                {
                                    buttonUrl = Model.Value<IPublishedContent>("button2DownloadFile")?.Url ?? "";
                                }
                                else if ((Model.Value("button2InternalLink") != null) && (Model.Value("button2InternalLink").ToString().Trim().Length > 0))
                                {
                                    buttonUrl = Model.Value<IPublishedContent>("button2InternalLink")?.Url ?? "";
                                    buttonTarget = "_self";
                                }
                                else if ((Model.Value("button2ScrollTo") != null) && (Model.Value("button2ScrollTo").ToString().Trim().Length > 0))
                                {
                                    buttonUrl = "#content-item-" + Model.Value("button2ScrollTo").ToString();
                                    buttonTarget = "_self";
                                    buttonScrollTo = true;
                                }
                            }
    
                            if (!string.IsNullOrEmpty(buttonUrl))
                            {
                                string alignClass = ((Model.Value("button2Align") != null) && (Model.Value("button2Align").ToString().Trim().Length > 0) && (!Model.Value("button2Align").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("button2Align").ToString().ToLower() : "left";
    
                                <div class="button-2 clearfix text-@alignClass"><a href="@((buttonScrollTo) ? buttonUrl : buttonUrl)" target="@buttonTarget" rel="noopener" aria-label="button2" title="" class="btn btn-secondary pull-@alignClass@((buttonScrollTo) ? " scroll-to" : string.Empty)">@Model.Value("button2Label")</a></div>
                            }
    
                            break;
                        }
                }
            }
        }
    }
    else
    {
    
        if ((Model.Value("first") != null) && (Model.Value("first").ToString().Trim().Length > 0) && (!Model.Value("first").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
        {
            layoutItems.Add(Model.Value("first").ToString());
        }
    
        if ((Model.Value("second") != null) && (Model.Value("second").ToString().Trim().Length > 0) && (!Model.Value("second").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
        {
            layoutItems.Add(Model.Value("second").ToString());
        }
    
        if ((Model.Value("third") != null) && (Model.Value("third").ToString().Trim().Length > 0) && (!Model.Value("third").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
        {
            layoutItems.Add(Model.Value("third").ToString());
        }
    
        if ((Model.Value("fourth") != null) && (Model.Value("fourth").ToString().Trim().Length > 0) && (!Model.Value("fourth").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
        {
            layoutItems.Add(Model.Value("fourth").ToString());
        }
    
        if ((Model.Value("fifth") != null) && (Model.Value("fifth").ToString().Trim().Length > 0) && (!Model.Value("fifth").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
        {
            layoutItems.Add(Model.Value("fifth").ToString());
        }
    
        if ((Model.Value("sixth") != null) && (Model.Value("sixth").ToString().Trim().Length > 0) && (!Model.Value("sixth").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
        {
            layoutItems.Add(Model.Value("sixth").ToString());
        }
    
        if ((Model.Value("seventh") != null) && (Model.Value("seventh").ToString().Trim().Length > 0) && (!Model.Value("seventh").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
        {
            layoutItems.Add(Model.Value("seventh").ToString());
        }
    
        if ((Model.Value("eighth") != null) && (Model.Value("eighth").ToString().Trim().Length > 0) && (!Model.Value("eighth").ToString().Equals(" - none -", System.StringComparison.OrdinalIgnoreCase)))
        {
            layoutItems.Add(Model.Value("eighth").ToString());
        }
    
        string titleUrl = (Model.Value("titleExternalUrl") != null) ? Model.Value("titleExternalUrl").ToString() : string.Empty;
        string titleTarget = "_blank";
        bool titleScrollTo = false;
    
        if (string.IsNullOrEmpty(titleUrl))
        {
            if ((Model.Value("titleDownloadFile") != null) && (Model.Value("titleDownloadFile").ToString().Trim().Length > 0))
            {
                titleUrl = Model.Value<IPublishedContent>("titleDownloadFile")?.Url ?? "";
            }
            else if ((Model.Value("titleInternalLink") != null) && (Model.Value("titleInternalLink").ToString().Trim().Length > 0))
            {
                titleUrl = Model.Value<IPublishedContent>("titleInternalLink")?.Url ?? "";
                titleTarget = "_self";
            }
            else if ((Model.Value("titleScrollTo") != null) && (Model.Value("titleScrollTo").ToString().Trim().Length > 0))
            {
                titleUrl = "#content-item-" + Model.Value("titleScrollTo").ToString();
                titleTarget = "_self";
                titleScrollTo = true;
            }
        }
    
        foreach (string layoutItem in layoutItems)
        {
            int columnWidth = Convert.ToInt32(Model.Value("columnWidth"));
            int headerStartIndex = 4;
    
            if ((columnWidth >= 9) && (columnWidth <= 12))
            {
                headerStartIndex = 2;
            }
            else if ((columnWidth >= 5) && (columnWidth <= 8))
            {
                headerStartIndex = 3;
            }
    
            switch (layoutItem.ToLower())
            {
                case "image":
                    {
                        var cropSelected = Model.Value("imageCropper");
                        var crop = (cropSelected != null && cropSelected.ToString().Trim().Length > 0) ? cropSelected.ToString() : "default";
                        string value = Model.GetCropUrl("image", @crop);
    
                        if (!string.IsNullOrEmpty(value))
                        {
                            <div class="image full-width text-left">
                                @if (!string.IsNullOrEmpty(titleUrl))
                                {
                                    @:<a href="@((titleScrollTo) ? titleUrl : titleUrl)" aria-label="text-left" rel="noopener" target="@titleTarget" title="@Model.Value("title")" @Html.Raw((titleScrollTo) ? " class=\"scroll-to\"" : string.Empty)>
                                    }
    
                                <img src="@value" alt="@Model.Value("title")" class="img-responsive" />
    
                                @if (!string.IsNullOrEmpty(titleUrl))
                                {
                                @:</a>
                            }
                            </div>
                        }
    
                        break;
                    }
    
                case "video":
                    {
    
                        string value = (Model.Value("video") != null) ? Model.Value("video").ToString() : string.Empty;
    
                        if (!string.IsNullOrEmpty(value))
                        {
                            value += ((value.IndexOf("?") > 0) ? "&" : "?") + "wmode=opaque";
    
                            <div class="video"><iframe src="@value" frameborder="0" width="560" height="315"></iframe></div>
                        }
    
                        break;
                    }
    
                case "title":
                    {
                        string value = (Model.Value("title") != null) ? Model.Value("title").ToString() : string.Empty;
    
                        if (!string.IsNullOrEmpty(value))
                        {
                            string alignClass = ((Model.Value("titleAlign") != null) && (Model.Value("titleAlign").ToString().Trim().Length > 0) && (!Model.Value("titleAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("titleAlign").ToString().ToLower() : "left";
    
                            <div class="title text-@alignClass">
                                @Html.Raw("<h" + headerStartIndex.ToString() + ">")
    
                                @if (!string.IsNullOrEmpty(titleUrl))
                                {
                                    @:<a href="@((titleScrollTo) ? titleUrl : titleUrl)" target="@titleTarget" rel="noopener" title="@value" @Html.Raw((titleScrollTo) ? " class=\"scroll-to\"" : string.Empty)>
                                    }
    
                                @value
                                "Test"
    
                                @if (!string.IsNullOrEmpty(titleUrl))
                                {
                                @:</a>
                            }
    
                                @Html.Raw("</h" + headerStartIndex.ToString() + ">")
                            </div>
                        }
    
                        break;
                    }
    
                case "subtitle":
                    {
                        string value = (Model.Value("subtitle") != null) ? Model.Value("subtitle").ToString() : string.Empty;
    
                        if (!string.IsNullOrEmpty(value))
                        {
                            string alignClass = ((Model.Value("subtitleAlign") != null) && (Model.Value("subtitleAlign").ToString().Trim().Length > 0) && (!Model.Value("subtitleAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("subtitleAlign").ToString().ToLower() : "left";
    
                            <div class="sub-title text-@alignClass">
                                @Html.Raw("<h" + (headerStartIndex + 1).ToString() + ">")
                                @value
                                "Test"
                                @Html.Raw("</h" + (headerStartIndex + 1).ToString() + ">")
                            </div>
                        }
    
                        break;
                    }
    
                case "description":
                    {
                        string value = (Model.Value("description") != null) ? Model.Value("description").ToString() : string.Empty;
    
                        if (!string.IsNullOrEmpty(value))
                        {
                            string alignClass = ((Model.Value("descriptionAlign") != null) && (Model.Value("descriptionAlign").ToString().Trim().Length > 0) && (!Model.Value("descriptionAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("descriptionAlign").ToString().ToLower() : "left";
    
                            <div class="description text-@alignClass">
                                @Html.Raw("<h" + (headerStartIndex + 2).ToString() + ">")
                                @value
                                "Test"
                                @Html.Raw("</h" + (headerStartIndex + 2).ToString() + ">")
                            </div>
                        }
    
                        break;
                    }
    
                case "text":
                    {
                        string value = (Model.Value("text") != null) ? Model.Value("text").ToString() : string.Empty;
    
                        if (!string.IsNullOrEmpty(value))
                        {
                            string alignClass = ((Model.Value("textAlign") != null) && (Model.Value("textAlign").ToString().Trim().Length > 0) && (!Model.Value("textAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("textAlign").ToString().ToLower() : "left";
    
                            <div class="text text-@alignClass" @Html.Raw(((Model.Value("textMinimumHeight") != null) && (Model.Value("textMinimumHeight").ToString().Trim().Length > 0)) ? " style=\"min-height:" + Model.Value("textMinimumHeight").ToString() + "px;\"" : string.Empty)>@Html.Raw("Test")</div>
                        }
                        break;
                    }
    
                case "button":
                    {
                        string buttonUrl = (Model.Value("buttonExternalUrl") != null) ? Model.Value("buttonExternalUrl").ToString() : string.Empty;
                        string buttonTarget = "_blank";
                        bool buttonScrollTo = false;
    
                        if (string.IsNullOrEmpty(buttonUrl))
                        {
                            if ((Model.Value("buttonDownloadFile") != null) && (Model.Value("buttonDownloadFile").ToString().Trim().Length > 0))
                            {
                                buttonUrl = Model.Value<IPublishedContent>("buttonDownloadFile")?.Url ?? "";
                            }
                            else if ((Model.Value("buttonInternalLink") != null) && (Model.Value("buttonInternalLink").ToString().Trim().Length > 0))
                            {
                                buttonUrl = Model.Value<IPublishedContent>("buttonInternalLink")?.Url ?? "";
                                buttonTarget = "_self";
                            }
                            else if ((Model.Value("buttonScrollTo") != null) && (Model.Value("buttonScrollTo").ToString().Trim().Length > 0))
                            {
                                buttonUrl = "#content-item-" + Model.Value("buttonScrollTo").ToString();
                                buttonTarget = "_self";
                                buttonScrollTo = true;
                            }
                        }
                        buttonUrlGlobabl = buttonUrl;
                        if (!string.IsNullOrEmpty(buttonUrl))
                        {
                            string alignClass = ((Model.Value("buttonAlign") != null) && (Model.Value("buttonAlign").ToString().Trim().Length > 0) && (!Model.Value("buttonAlign").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("buttonAlign").ToString().ToLower() : "left";
    
                            <div id="button1" class="button clearfix text-@alignClass"><a href="@((buttonScrollTo) ? buttonUrl : buttonUrl)" title="" rel="noopener" class="btn btn-primary pull-@alignClass@((buttonScrollTo) ? " scroll-to" : string.Empty)">@Model.Value("buttonLabel")</a></div>
                        }
    
                        break;
                    }
    
                case "button 2":
                    {
                        string buttonUrl = (Model.Value("button2ExternalUrl") != null) ? Model.Value("button2ExternalUrl").ToString() : string.Empty;
                        string buttonTarget = "_blank";
                        bool buttonScrollTo = false;
    
                        if (string.IsNullOrEmpty(buttonUrl))
                        {
                            if ((Model.Value("button2DownloadFile") != null) && (Model.Value("button2DownloadFile").ToString().Trim().Length > 0))
                            {
                                buttonUrl = Model.Value<IPublishedContent>("button2DownloadFile")?.Url ?? "";
                            }
                            else if ((Model.Value("button2InternalLink") != null) && (Model.Value("button2InternalLink").ToString().Trim().Length > 0))
                            {
                                buttonUrl = Model.Value<IPublishedContent>("button2InternalLink")?.Url ?? "";
                                buttonTarget = "_self";
                            }
                            else if ((Model.Value("button2ScrollTo") != null) && (Model.Value("button2ScrollTo").ToString().Trim().Length > 0))
                            {
                                buttonUrl = "#content-item-" + Model.Value("button2ScrollTo").ToString();
                                buttonTarget = "_self";
                                buttonScrollTo = true;
                            }
                        }
    
                        if (!string.IsNullOrEmpty(buttonUrl) || buttonScrollTo == false)
                        {
                            string alignClass = ((Model.Value("button2Align") != null) && (Model.Value("button2Align").ToString().Trim().Length > 0) && (!Model.Value("button2Align").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("button2Align").ToString().ToLower() : "left";
    
                            <div class="button-2 clearfix text-@alignClass"><a href="@buttonUrl" target="@buttonTarget" title="" rel="noopener" class="btn btn-secondary pull-@alignClass@((buttonScrollTo) ? " scroll-to" : string.Empty)">@Model.Value("button2Label")</a></div>
                        }
                        else
                        {
                            string alignClass = ((Model.Value("button2Align") != null) && (Model.Value("button2Align").ToString().Trim().Length > 0) && (!Model.Value("button2Align").ToString().Equals("- default -", System.StringComparison.OrdinalIgnoreCase))) ? Model.Value("button2Align").ToString().ToLower() : "left";
    
                            <div class="button-2 clearfix text-@alignClass"><a href="@((buttonScrollTo) ? buttonUrl : buttonUrl)" target="@buttonTarget" title="" rel="noopener" class="btn btn-secondary pull-@alignClass@((buttonScrollTo) ? " scroll-to" : string.Empty)">@Model.Value("button2Label")</a></div>
                        }
    
                        break;
                    }
            }
        }
    }
    

    }

Please Sign in or register to post replies

Write your reply to:

Draft