Copied to clipboard

Flag this post as spam?

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


  • oguru 5 posts 75 karma points
    Nov 09, 2020 @ 11:04
    oguru
    0

    Cannot bind source content type Umbraco.Web.PublishedModels.Contact to model type Umbraco.Web.PublishedModels.Home error

    Hi

    I'm quite new to Umbraco, c# and asp.net and i've run into this problem:

    Cannot bind source content type Umbraco.Web.PublishedModels.Contact to model type Umbraco.Web.PublishedModels.Home. 
    Both view and content models are PureLive, with same version. The application is in an unstable state and should be restarted.
    

    I've made a few pages on various test projects that worked fine.

    On my current project i've just added a contact page and i get the error in the title when i try to access it. I'm following a Udemy course called "OK, Umbraco" and it works fine in his project.

    It says the source error is coming from this line in my master template:

    @Html.Partial("~/Views/Partials/Navigation.cshtml")
    

    Inside my Navigation.cshtml I have:

    @inherits 
    
    Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Home>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{ 
        var homePage = Model.AncestorOrSelf<Home>();
    }
    
    <!-- Navigation -->
    <nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav">
        <div class="container">
            <a class="navbar-brand" href="index.html">Bluelight Portal</a>
            <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
                Menu
                <i class="fas fa-bars"></i>
            </button>
            <div class="collapse navbar-collapse" id="navbarResponsive">
                <ul class="navbar-nav ml-auto">
                    @foreach (var page in homePage.Children.Where(w => w.IsVisible()))
                    {
                        <li class="nav-item">
                            <a class="nav-link" href="@page.Url">@page.Name</a>
                        </li>
                    }
                </ul>            
            </div>
        </div>
    </nav>
    

    Home.cshtml (which works fine):

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Home>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = "Master.cshtml";
    }
    
    @Html.Partial("Header")
    

    Contact.cshtml:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Contact>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = "Master.cshtml";
    }
    
    @Html.Partial("Header")
    

    If I remove the Navigation partial the contact page renders, but it works fine on the home page and in another project on all the pages.

    I don't understand why it's not working if contact and home are the same apart from the ContentModel which i believe is correct. I've done some searching on this error but it seems like each case is different and none matched my own.

    I'd be incredibly grateful if anyone could help me! Feeling a little overwhelmed with how little I understand everything at the moment.

    Thanks

  • Ole Martin Bakke 112 posts 624 karma points
    Nov 09, 2020 @ 13:50
    Ole Martin Bakke
    0

    Your navigation.cshtml expects a model of type Home, when you render the contact-page the model will be wrong.

    You can change your navigation.cshtml to expect the default model IPublishedContent by changing your first line to:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    

    Just drop the

  • oguru 5 posts 75 karma points
    Nov 09, 2020 @ 14:23
    oguru
    0

    Amazing, thank you so much! I've been having quite a rough day and this has improved it drastically :)

Please Sign in or register to post replies

Write your reply to:

Draft