Copied to clipboard

Flag this post as spam?

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


  • Leon Hancock 3 posts 74 karma points
    Feb 24, 2023 @ 16:50
    Leon Hancock
    0

    Search view model exception

    Hi,

    I'm currently looking at setting up the Examine search within Umbraco to provide a site search for content. I've followed the quick start guide here and everything works fine until I use a layout for the search page template.

    When I submit the search form using a layout I receive the following exception:

    enter image description here

    Has anyone else come across this, and if so, would you be able to give me a nudge in the right direction please?

    Thanks, Leon

  • Johannes Lantz 156 posts 838 karma points c-trib
    Feb 24, 2023 @ 18:57
    Johannes Lantz
    0

    Hi Leon!

    I believe you need to change your @inherits at the top of your view. So it's the type of SearchViewModel instead of IMetaData. Something like this:

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<BCBC.Intranet.Core.ViewModels.SearchViewModel>
    

    Hope this helps!

    //Johannes

  • Leon Hancock 3 posts 74 karma points
    Feb 27, 2023 @ 07:55
    Leon Hancock
    0

    Hi Johannes,

    Thanks for the response.

    Unfortunately it has already been changed. In the view I have:

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<SearchViewModel>
    @{
        Layout = "Layout.cshtml";
    }
    

    The layout just inherits from:

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    

    Thanks, Leon

  • Leon Hancock 3 posts 74 karma points
    Feb 28, 2023 @ 09:31
    Leon Hancock
    1

    Just wanted to post an update.

    The issue was arising due to the document types using a composition for the page metadata. Within the layout, there was a partial view to render these metatags, which is why the model binder was trying to bind to IMetadata.

    In the end I scrapped the view model and extended the model builder class for the search document type with the properties from the view model. That way it was always implementing IMetadata.

  • Henrik Sunesen 84 posts 281 karma points
    Feb 21, 2024 @ 19:56
    Henrik Sunesen
    0

    Hi Leon

    I'm facing the exact same problem.

    Can you show how you managed to solved it :)?

Please Sign in or register to post replies

Write your reply to:

Draft