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.
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.
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.
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.
Actually, the PublishedContentWrapped worked! I had to inject some stuff into the creation of the viewModel:
var viewModel = new ViewModels.SiteSearchViewModel(CurrentPage, _publishedValueFallback);
@Travis can you share some code to help on this case.
is working on a reply...