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 5 posts 85 karma points
    15 days ago
    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 5 posts 85 karma points
    15 days ago
    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);

Please Sign in or register to post replies

Write your reply to:

Draft