Copied to clipboard

Flag this post as spam?

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


  • Davide Agosti 3 posts 103 karma points
    Nov 16, 2016 @ 16:56
    Davide Agosti
    0

    Master template

    I have a problem with this code, any help is appreciate the error code is Object reference not set to an instance of an object. I try to get the value from a document types from home page and put in masterpage.

    IPublishedContent homePage = Model.Content.AncestorOrSelf(1); IPublishedContent currPage = Model.Content; Pagehome headerHomePage = currPage.Descendant

    int headerType = (headerHomePage.HeaderHomeType == null) ? -1 : (int)headerHomePage.HeaderHomeType; string headerTypeStr = (headerType == -1) ? "Static Sticky" : umbraco.library.GetPreValueAsString(headerType);

    switch (headerTypeStr)
    {
        case "Transparent":
            headerHomeClass = "transparent-header";
            headerDataClass = "data-sticky-class='not-dark'";
            break;
        case "Semi Transparent":
            headerHomeClass = "transparent-header semi-transparent";
            break;
        case "Left Side":
            headerHomeClass = "no-sticky";
            break;
        case "Right Side":
            headerHomeClass = "no-sticky";
            break;
        case "Floating":
            headerHomeClass = "transparent-header floating-header";
            break;
        case "Static Sticky":
            headerHomeClass = "static-sticky";
            break;
        case "Alternate Logos":
            headerHomeClass = string.Empty;
            break;
        default:
            headerHomeClass = string.Empty;
            break;
    }
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Nov 16, 2016 @ 17:16
    Alex Skrypnyk
    0

    Hi Davide,

    I think headerHomePage can be null.

    Can you share all code?

  • Davide Agosti 3 posts 103 karma points
    Nov 16, 2016 @ 20:13
    Davide Agosti
    0

    no, because I tried, but here the code the View is a master Template: `

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using ClientDependency.Core.Mvc;
    @using DotSee.PropSense;
    @using DotSee.PageMetas;
    @using DotSee.UmbracoExtensions;
    @{
        Layout = null;
    `
        IPublishedContent homePage = Model.Content.AncestorOrSelf(1);
        IPublishedContent currPage = Model.Content;
        ConfigGlobalSettings configPage
    homePage.Descendant<ConfigGlobalSettings>();
    
        //Check if page redirects to first subpage
        currPage.CheckRedirectFirstSubPage();
    
        Html.RequiresJs("/scripts/jquery.js");
    
    
        MetaSettings settings = configPage.GetMetaSettings();
    }
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        @Html.CachedPartial("PageMetas", Model.Content, 300, true, false, new ViewDataDictionary { { "MetaSettings", settings } })
        @Html.CachedPartial("PageIcons", Model.Content, 300, true, false)
        <!-- Stylesheets -->
        <link rel="stylesheet" type="text/css" href="/css/bootstrap-3.3.7/css/bootstrap.min.css" />
    
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
        <!--[if lt IE 9]>
    
    
        <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
    
    
        <![endif]-->
        <!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->
        @Html.Raw(configPage.ScriptInHeadElement)
    </head>
    @{
        <!-- Home Page Header (Local Variables) Setting -->
        string headerHomeClass = "";
        string headerDataClass = "";
        string bodyCssClass = "";
        string headerTriger = "";
        <!-- Home Page Header Code Setting -->
        Pagehome headerHomePage = currPage.Descendant<Pagehome>();
        int headerType = (headerHomePage.HeaderHomeType == null) ? -1 : (int)headerHomePage.HeaderHomeType;
        string headerTypeStr = (headerType == -1) ? "Static Sticky" : umbraco.library.GetPreValueAsString(headerType);
    
    
        switch (headerTypeStr)
        {
            case "Transparent":
                headerHomeClass = "transparent-header";
                headerDataClass = "data-sticky-class='not-dark'";
                break;
            case "Semi Transparent":
                headerHomeClass = "transparent-header semi-transparent";
                break;
            case "Left Side":
                headerHomeClass = "no-sticky";
                break;
            case "Right Side":
                headerHomeClass = "no-sticky";
                break;
            case "Floating":
                headerHomeClass = "transparent-header floating-header";
                break;
            case "Static Sticky":
                headerHomeClass = "static-sticky";
                break;
            case "Alternate Logos":
                headerHomeClass = string.Empty;
                break;
            default:
                headerHomeClass = string.Empty;
                break;
        }
    
        int sideOptions = (headerHomePage.SideHeaderOptions == null) ? -1 : (int)headerHomePage.SideHeaderOptions;
        string sideOptionsStr = (sideOptions == -1) ? "Fixed Position" : umbraco.library.GetPreValueAsString(sideOptions);
    
        if (headerTypeStr == "Left Side")
        {
            switch (sideOptionsStr)
            {
                case "Fixed Position":
                    bodyCssClass = "side-header";
                    break;
                case "OnClick Open":
                    bodyCssClass = "side-header open-header close-header-on-scroll";
                    headerTriger = "<div id=\"header-trigger\"><i class=\"icon-line-menu\"></i><i class=\"icon-line-cross\"></i></div>";
                    break;
                case "Push Content":
                    bodyCssClass = "side-header open-header push-wrapper close-header-on-scroll";
                    headerTriger = "<div id=\"header-trigger\"><i class=\"icon-line-menu\"></i><i class=\"icon-line-cross\"></i></div>";
                    break;
                default:
                    bodyCssClass = string.Empty;
                    break;
            }
        }
        else if (headerTypeStr == "Right Side")
        {
            switch (sideOptionsStr)
            {
                case "Fixed Position":
                    bodyCssClass = "side-header side-header-right";
                    break;
                case "OnClick Open":
                    bodyCssClass = "side-header side-header-right open-header close-header-on-scroll";
                    headerTriger = "<div id=\"header-trigger\"><i class=\"icon-line-menu\"></i><i class=\"icon-line-cross\"></i></div>";
                    break;
                case "Push Content":
                    bodyCssClass = "side-header side-header-right open-header push-wrapper close-header-on-scroll";
                    headerTriger = "<div id=\"header-trigger\"><i class=\"icon-line-menu\"></i><i class=\"icon-line-cross\"></i></div>";
                    break;
                default:
                    bodyCssClass = string.Empty;
                    break;
            }
        }
    
        <!-- Global Header (Local Variables) Setting -->
        string stretchCssClass = "";
        string headerTextCssClass = "";
        string headerCssClass = "";
    
        <!-- Global Header Code Setting -->
        int stretchOptions = (configPage.FullWidthHeader == null) ? -1 : (int)configPage.FullWidthHeader;
        string stretchOptionsStr = (stretchOptions == -1) ? "Width" : umbraco.library.GetPreValueAsString(stretchOptions);
    
        if (stretchOptionsStr != "Width")
        {
            stretchCssClass = "full-header";
        }
        else
        {
            stretchCssClass = string.Empty;
        }
    
        int headerTextClass = (configPage.LightDark == null) ? -1 : (int)configPage.LightDark;
        string headerTextStr = (headerTextClass == -1) ? "Light" : umbraco.library.GetPreValueAsString(headerTextClass);
    
        if (headerTextStr != "Light")
        {
            headerTextCssClass = "dark";
        }
        else
        {
            headerTextCssClass = string.Empty;
        }
    
        int headerglobalType = (configPage.HeaderGlobalType == null) ? -1 : (int)configPage.HeaderGlobalType;
        string headerGlobalTypeStr = (headerglobalType == -1) ? "Static Sticky" : umbraco.library.GetPreValueAsString(headerglobalType);
    
        switch (headerGlobalTypeStr)
        {
            case "Semi Transparent":
                headerCssClass = "transparent-header semi-transparent";
                break;
            case "Static Sticky":
                headerCssClass = "static-sticky";
                break;
            case "Alternate Logos":
                headerCssClass = string.Empty;
                break;
            default:
                headerCssClass = string.Empty;
                break;
        }
    
    
        string headCssClass = "";
        headCssClass = (
            (currPage.HasProperty(Psn_Pagehome.lightTopMenu) && currPage.GetPropertyValue<bool>(Psn_Pagehome.lightTopMenu))
            ||
            (currPage.DocumentTypeAlias == PageArticleItem.ModelTypeAlias && currPage.Ancestor<PageBlogList>().PostsInheritBackgroundImage && currPage.Ancestor<PageBlogList>().LightTopMenu)
            ||
            (currPage.DocumentTypeAlias == PagePortfolioItem.ModelTypeAlias && currPage.Ancestor<SectionPortfolio>().InheritBackgroundImage && currPage.Ancestor<PageContent>().LightTopMenu)
            ) ? "Light" : "dark";
    
    }
    <body class="stretched @bodyCssClass @headerHomePage">
        @Html.Raw(configPage.ScriptAfterBodyStart)
        <!-- Document Wrapper Start -->
        <div id="wrapper" class="clearfix">
            <!-- Preloader Start -->
            <section id="preloader">
                <div class="loader" id="loader">
                    <div class="loader-img"></div>
                </div>
            </section>
            <!-- Preloader End -->
            <!-- Header-Triger Show Start -->
            @Html.Raw(headerTriger)
            <!-- Header-Triger Show Start -->
            <!-- Header Start -->
            <header id="header" class="@stretchCssClass @headerCssClass @headerHomeClass @headerTextCssClass" @Html.Raw(headerDataClass)>
                <div id="header-wrap">
                    <div class="container clearfix">
                        <div id="primary-menu-trigger"><i class="icon-reorder"></i></div>
                        <!-- Logo -->
                        <div id="logo">
                            @Html.CachedPartial("PageLogo", Model.Content, 3600, true)
                        </div><!-- #logo end -->
                        <!-- Primary Navigation -->
                        <nav id="primary-menu">
                            @Html.CachedPartial("PageMenuTop", Model.Content, 3600, true)
                            <!-- Top Search -->
                            <div id="top-search">
                                <a href="#" id="top-search-trigger"><i class="icon-search3"></i><i class="icon-line-cross"></i></a>
                                <form action="search.html" method="get">
                                    <input type="text" name="q" class="form-control" value="" placeholder="Type &amp; Hit Enter..">
                                </form>
                            </div><!-- #top-search end -->
                        </nav><!-- #primary-menu end -->
                    </div>
                </div>
            </header><!-- Header End -->
            <!-- Slider Start -->
            @RenderSection("Intro_Section", required: false)
            <!-- Slider End-->
            <!-- Content Start -->
            <section id="content">
                @RenderBody()
            </section><!-- Content End -->
            @Html.CachedPartial("PageFooter", Model.Content, 3600, true)
            <!-- Go To Top Start -->
            <div id="gotoTop" class="icon-angle-up"></div>
            <!-- Go To Top End -->
        </div><!-- Document Wrapper End -->
        @Html.RenderJsHere()
        @Html.Raw(configPage.ScriptBeforeBodyEnd)
    </body>
    </html>
    
  • Davide Agosti 3 posts 103 karma points
    Nov 16, 2016 @ 21:43
    Davide Agosti
    100

    Hi, I found the issue, I have to change the instuctions
    From Pagehome headerHomePage = currPage.Descendant<Pagehome>(); To Pagehome headerHomePage = (Pagehome)homePage;
    now everything work fine.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Nov 16, 2016 @ 21:52
    Alex Skrypnyk
    0

    Hi Davide,

    Glad that you solved the issue.

    Have a nice evening!

    Thanks

    /Alex

Please Sign in or register to post replies

Write your reply to:

Draft