Copied to clipboard

Flag this post as spam?

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


  • Aki Ruuskanen 7 posts 47 karma points
    Jan 31, 2020 @ 09:02
    Aki Ruuskanen
    0

    Model error in template

    Hi,

    I have problem when creating new pages. All new pages gets the error I have pasted below.

    The error occurs when accessing the Model.

    @Model.Name

    The template inherits from UmbracoViewPage.

    I have a number of pages that uses the same template and they work fine. Only new pages gets this error.

    ModelsMode is "Dll".

    I have tried the "Rebuild" and "Reload" in "Published status".

    Example : https://eftersandning.se/ta-bort/

    Umbraco version : 8.1

    Does anyone have any ideas?

    [NullReferenceException: Object reference not set to an instance of an object.] ASP.PageViewskampanjmastercshtml.Execute() in C:\inetpub\wwwroot\tackeftersandning\Views\kampanjmaster.cshtml:40 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +251 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +147 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +121 System.Web.WebPages.<>cDisplayClass400.0(TextWriter writer) +308 System.Web.WebPages.WebPageBase.Write(HelperResult result) +107 System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action1 body) +88 System.Web.WebPages.WebPageBase.PopContext() +309 Umbraco.Web.Mvc.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +179 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +377 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +90 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +793 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +793 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +793 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +81 System.Web.Mvc.Async.<>cDisplayClass31.1(IAsyncResult asyncResult) +188 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38 System.Web.Mvc.<>c.

    Regards / Aki

  • Ambert van Unen 65 posts 376 karma points
    Jan 31, 2020 @ 13:35
    Ambert van Unen
    0

    When looking at your URL you're accessing "@home.Name", perhaps you forgot to do something like:

       var home = Model;
    

    Have you tried just using @Model.Name?

  • Aki Ruuskanen 7 posts 47 karma points
    Jan 31, 2020 @ 13:54
    Aki Ruuskanen
    0

    Thanks for the feedback.

    I actually had @Model.Name there first. Same error with it.

    I changed it to:

    var home = (Kampanjsida)Model.Root();
    
    <title>@home.Name</title>
    

    Regards / Aki

  • Ambert van Unen 65 posts 376 karma points
    Jan 31, 2020 @ 14:00
    Ambert van Unen
    0

    Odd, it should work by default.

    Perhaps there was something wrong in your @inherits ?

    Good that it works for now ;-)

  • Aki Ruuskanen 7 posts 47 karma points
    Jan 31, 2020 @ 14:04
    Aki Ruuskanen
    0

    I still get the same error.

    Other pages with exact same templates work:

    Example : https://eftersandning.se/att-vilja-leva-sjalvforsorjande-allt-mer-populart/

    New pages dont work. Created a new test page.

    https://eftersandning.se/ta-bort/

  • Ambert van Unen 65 posts 376 karma points
    Jan 31, 2020 @ 14:07
    Ambert van Unen
    0

    If old pages work, and new ones don't, do the old pages, when republished, stop working as well? It could be that the old ones are cached.

    Can you show a sample of the code ? Where you declare the using / inherits ? I think you have an error somewhere..

  • Aki Ruuskanen 7 posts 47 karma points
    Jan 31, 2020 @ 14:19
    Aki Ruuskanen
    0

    I'd rather not try to republish and risk that the page will break. There are ongoing campaigns in social media with links to those pages. :)

    Yes, here is the HEAD. Stripped out some unimportant stuff.

    @using Umbraco.Core.PropertyEditors
    @inherits UmbracoViewPage<Kampanjsida>
    @{
        Layout = null;
    
        var home = (Kampanjsida)Model.Root();
        var thumbnailImage = (Image)Model.Value("thumbnailImage");
        var topLogotype = (Image)Model.Value("topLogotype");
        var topLogotypeLink = (string)Model.Value("topLogotypeLink");     
    }
    
    <!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <title>@home.Name</title>
        <meta name="description" content="">
        <meta name="author" content="">
    
        <meta property=”og:title” content="@home.Name" />
        <meta property=”og:url” content="@home.Url" />
        <meta property=”og:type” content="article" />
        <meta property=”og:description” content="@Model.SeoMetaDescription" />
        <meta property=”og:image” content="@thumbnailImage.Url" />
    
        @RenderSection("Header", required: false)
    </head>
    
  • Aki Ruuskanen 7 posts 47 karma points
    Feb 03, 2020 @ 11:46
    Aki Ruuskanen
    0

    I have setup the site locally and get the same behviour. I tried to unpublish a working page and the publish it again. And it works fine.

  • Ambert van Unen 65 posts 376 karma points
    Jan 31, 2020 @ 14:28
    Ambert van Unen
    0

    Hmm odd, the code looks fine. I've tried it on my own project and it works as expected..

    The only thing I can imagine is that your "Kampanjsida" does not have a Name property.. But that would be a bit odd.

    I'm inclined to think it has something to do with your ModelBuilder. Have you perhaps recently updated to 8.5?

    But FIRST: I'd try to NOT do anything more on the live version, try to fix it locally first, so that you have some backup ;-)

  • Aki Ruuskanen 7 posts 47 karma points
    Jan 31, 2020 @ 14:34
    Aki Ruuskanen
    0

    Thanks for your input.

    It's running on 8.1.

    Very odd indeed. I have not touched it and the customer has been working with it for a couple of months. And then suddenly with a new page this happends.

    I will try to reproduce locally.

    Regards / Aki

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Jan 31, 2020 @ 15:35
    Alex Skrypnyk
    0

    Hi Aki

    Maybe something happened to Models builder or Umbraco cache?

    Did you try to restart an app?

    Alex

  • Aki Ruuskanen 7 posts 47 karma points
    Feb 03, 2020 @ 12:43
    Aki Ruuskanen
    100

    Hi,

    This is now solved.

    I have a field called "thumbnailIImage" in the document and that was not set as mandatory even though the template uses the field.

    So the new pages were saved without that field set.

    Thanks for all suggestions and feedback.

    Regards / Aki

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies