Copied to clipboard

Flag this post as spam?

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


  • J. de K. 9 posts 89 karma points
    Sep 12, 2022 @ 08:52
    J. de K.
    0

    PAYING 50 EUR - Help me fix Umbraco.Web.Mvc.ModelBindingException

    Anyone know what may be the issue? I am getting this error:

    Umbraco.Web.Mvc.ModelBindingException: Cannot bind source content type [redacted].Web.ViewModels.PageNotFound to model type [redacted].Web.ViewModels.Subpage.

    The error arises when trying to load a 404 error page of document type 'Errorpage'. I am new to Umbraco so I am not entirely sure how to decode the message, but googling suggests that it may be because of this line in /Views/Subpage.cshtml?

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<[redacted].Web.ViewModels.Subpage> @using ContentModels = Umbraco.Web.PublishedModels

    After spending so much time trying to fix this I am pretty desperate at this point so I am paying 50 eur if you can help me fix this (although transaction costs may be deducted from this if you're outside the EU)

  • Patrick de Mooij 72 posts 622 karma points MVP 3x c-trib
    Sep 12, 2022 @ 09:18
    Patrick de Mooij
    100

    Hi,

    Your issue here is that the code is trying to render a .cshtml page that is expecting a [redacted].Web.ViewModels.Subpage (coming from the @inherits Umbraco.Web.Mvc.UmbracoViewPage<[redacted].Web.ViewModels.Subpage>), however your code is sending a [redacted].Web.ViewModels.PageNotFound thus is cannot render the view due to a wrong model

    Could you try changing @inherits Umbraco.Web.Mvc.UmbracoViewPage<[redacted].Web.ViewModels.Subpage> to @inherits Umbraco.Web.Mvc.UmbracoViewPage<[redacted].Web.ViewModels.PageNotFound>?

  • J. de K. 9 posts 89 karma points
    Sep 12, 2022 @ 09:46
    J. de K.
    0

    Thanks for the response. The thing that confuses me is that there is no template for pageNotFound, only for subpage.

    This line is in the Subpage template @inherits Umbraco.Web.Mvc.UmbracoViewPage<[redacted].Web.ViewModels.Subpage>. The Subpage template is used successfully for some other pages so I I think if I change ViewModels.Subpage to ViewModels.PageNotFound it would break those.

    Honestly, I am confused about where pageNotFound even gets @inherits Umbraco.Web.Mvc.UmbracoViewPage<Raido.Web.ViewModels.Subpage> from as in the I can't find pageNotFound document type I can't find any reference to Subpage...

    BTW, I inherited this codebase and was thrown in the deep end as I never worked with Umbraco before so my apologies if I am not much help.

  • Patrick de Mooij 72 posts 622 karma points MVP 3x c-trib
    Sep 12, 2022 @ 09:51
    Patrick de Mooij
    1

    Yeah, if you would change that line while it is used in other places, it will break them.

    The reference to the template could come from a few places. You could check the following:

    1. Document type under the content app "Templates", but it sounds like you already check this one.
    2. The content type under the content app "Info". There should be a dropdown under a header "Template". Sometimes it is shown empty while there is actually a template under it. Might be handy to republish just in case.
    3. The pageNotFound could be set through a IContentLastChanceFinder. The template could also be set dynamically in this finder.
    4. Maybe you have a plugin installed that influences this.

    Best thing would probably be to either have the PageNotFound document type inherit from the Subpage so that you can use the same template. Or create a specific pageNotFound template and link it with that.

  • J. de K. 9 posts 89 karma points
    Sep 12, 2022 @ 10:35
    J. de K.
    0

    The content type under the content app "Info". There should be a dropdown under a header "Template". Sometimes it is shown empty while there is actually a template under it. Might be handy to republish just in case.

    This was actually the case! There are no dropdown options but when I select open it open the Subpage template.

    I am down for either solution but I get stuck here:

    • For the first solution, I'm in the PageNotFound document type but I don't know how to change it to inherit from the Subpage document type. Following this article I went into Compositions and I see an option to select /Layout/Reusable ribbons/reusable ribbons but no option for the Subpage document type which is /Layout/Reusable ribbons/Subpage

    • For the second solution, I created another template pageNotFound.cshtml but I can't select the error page to use this as the dropdown is empty.

  • Patrick de Mooij 72 posts 622 karma points MVP 3x c-trib
    Sep 12, 2022 @ 10:55
    Patrick de Mooij
    1

    For the first solution, you'll probably have to move the PageNotFound document type to be under the Subpage document type. Ofcourse, I don't know the complete structure of your Umbraco, so I would suggest trying to do the second solution first.

    As for the second solution. Did you also add the new template to your document type here? enter image description here

    If it isn't added there, then it also won't show as one of the options in the dropdown.

  • J. de K. 9 posts 89 karma points
    Sep 12, 2022 @ 11:12
    J. de K.
    0

    Thanks for the help so far! The template not being added to the document type was indeed the problem with the dropdown. I am still getting the error but I think we are close to fixing it. Here is the current status:

    The errorpage is now using the template PageNotFound enter image description here

    Which is inheriting Subpage like below (not sure if this is correct) enter image description here

  • Patrick de Mooij 72 posts 622 karma points MVP 3x c-trib
    Sep 12, 2022 @ 11:16
    Patrick de Mooij
    1

    Yes, almost there! In your pageNotFound.cshtml, you should now change the @inherits Umbraco.Web.Mvc.UmbracoViewPage<[Redacted].Web.ViewModels.Subpage> to @inherits Umbraco.Web.Mvc.UmbracoViewPage<[Redacted].Web.ViewModels.PageNotFound>

    As the page should expect a model of type PageNotFound instead of type Subpage

  • J. de K. 9 posts 89 karma points
    Sep 12, 2022 @ 11:30
    J. de K.
    0

    YESSSSSS IT WORKS! Amazing help, thanks so much for the step-by-step help and patience! Based on your name I am thinking you are Dutch? Could you send me your IBAN or create a tikkie?

  • Patrick de Mooij 72 posts 622 karma points MVP 3x c-trib
    Sep 12, 2022 @ 11:35
    Patrick de Mooij
    0

    Great to hear that it works! And don't worry about the money, I am just glad to help people out.

  • J. de K. 9 posts 89 karma points
    Sep 12, 2022 @ 12:03
    J. de K.
    0

    Very generous of you, I'll pay it forward!

  • Pasang Tamang 258 posts 458 karma points
    Sep 12, 2022 @ 09:19
    Pasang Tamang
    1

    Hi,

    It looks there is some thing to do with template assign. If you assign wrong template in 404 document type then this issue will come. In your 404 page, please make sure you do not have subpage template assigned?

    Thanks,

    Pasang

Please Sign in or register to post replies

Write your reply to:

Draft