Copied to clipboard

Flag this post as spam?

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


  • Prateek 1 post 71 karma points
    Mar 08, 2022 @ 14:42
    Prateek
    0

    Cannot bind source type to model type Umbraco.Cms.Core.Models.PublishedContent.IPublishedContent

    I keep getting below error while trying to bind a custom model to the view. I did the route hijacking using RenderController and then in the action method, I am trying to return a custom model to the view. It gives below error. It gets resolved when I remove the Layout page reference from the view. But shows up when layout is included in the view.

    ModelBindingException: Cannot bind source type WMDCExternalSitesBase.Core.Models.ComposedPageViewModel`2[[Umbraco.Cms.Web.Common.PublishedModels.Search, WMDCExternalSitesBase.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[WMDCExternalSitesBase.Core.Models.SearchResultModel, WMDCExternalSitesBase.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] to model type Umbraco.Cms.Core.Models.PublishedContent.IPublishedContent.

  • Travis 19 posts 99 karma points
    May 12, 2022 @ 19:24
    Travis
    0

    Same thing is happening to me. I can remove the "inherits" from the master template and it fixes it, but then I don't get access to the model.

    I tried the PublishContentWrapped mentioned here: https://our.umbraco.com/documentation/reference/routing/custom-controllers

    But it still throws the same error. It's like the master page is overriding the route-hijacked template's defined model with IPublishedContent instead of MyCustomViewModel.

  • Travis 19 posts 99 karma points
    May 12, 2022 @ 19:30
    Travis
    0

    Actually, the PublishedContentWrapped worked! I had to inject some stuff into the creation of the viewModel:

    var viewModel = new ViewModels.SiteSearchViewModel(CurrentPage, _publishedValueFallback);

  • Sayed Muhammad Idrees 7 posts 77 karma points
    Nov 19, 2024 @ 09:30
    Sayed Muhammad Idrees
    0

    @Travis can you share some code to help on this case.

  • 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