Receiving ModelBindingException error, but no indication of what's causing it
I've recently begun the process of merging our Umbraco instances into a new multisite instance, using uSync to bring over the existing content. For the most part, everything is working fine but I've encountered a strange issue with 3 template files (so far) despite them using the same code as other templates connected to the same Master layout.
ModelBindingException: Cannot bind source content type Umbraco.Cms.Web.Common.PublishedModels.MagazineIndex to model type Umbraco.Cms.Web.Common.PublishedModels.Master. Both view and content models are in memory generated, with same version. The application is in an unstable state and should be restarted.
My first thought was to try removing the Master document type as a composition on this MagazineIndex type, but that didn't change anything. I then wondered if it was maybe an issue with the partial views in the Master template, so I removed those and still had the same error.
I then tried copying the contents of the Master layout over to the MagazineIndex template, replacing the @RenderBody() tag with the code from the MagazineIndex template... and it worked (as long as the template was set to Layout = null;).
What I can't understand though is why this works here when it's basically the same as if I added Layout = "Master.cshtml"; to the MagazineIndex template. Is this something to do with the ModelsBuilder setup (which is set to the defaults on this instance) or am I overlooking something?
It's also strange because this is working perfectly on other templates, but not here. I could obviously just copy over the code from the Master template and run with that, but that wouldn't resolve the underlying issue if it comes up in the future.
I probably didn't have the same problem as you, but as your problem just made me find what was wrong with my setup I am writing nontheless.
In my case Umbraco 13 had created a template with the wrong name, based on the public display name for the content type rather than the model name. So my new content type had two different templates without me knowing. As I am using custom controllers this did not throw the expected error. I checked under Allowed Templates for my content type and found the impostor.
Receiving ModelBindingException error, but no indication of what's causing it
I've recently begun the process of merging our Umbraco instances into a new multisite instance, using uSync to bring over the existing content. For the most part, everything is working fine but I've encountered a strange issue with 3 template files (so far) despite them using the same code as other templates connected to the same Master layout.
My first thought was to try removing the Master document type as a composition on this MagazineIndex type, but that didn't change anything. I then wondered if it was maybe an issue with the partial views in the Master template, so I removed those and still had the same error.
I then tried copying the contents of the Master layout over to the MagazineIndex template, replacing the
@RenderBody()
tag with the code from the MagazineIndex template... and it worked (as long as the template was set toLayout = null;
).What I can't understand though is why this works here when it's basically the same as if I added
Layout = "Master.cshtml";
to the MagazineIndex template. Is this something to do with the ModelsBuilder setup (which is set to the defaults on this instance) or am I overlooking something?It's also strange because this is working perfectly on other templates, but not here. I could obviously just copy over the code from the Master template and run with that, but that wouldn't resolve the underlying issue if it comes up in the future.
Master.cshtml
MagazineIndex.cshtml
Any help on this would be much appreciated, thanks!
I probably didn't have the same problem as you, but as your problem just made me find what was wrong with my setup I am writing nontheless.
In my case Umbraco 13 had created a template with the wrong name, based on the public display name for the content type rather than the model name. So my new content type had two different templates without me knowing. As I am using custom controllers this did not throw the expected error. I checked under Allowed Templates for my content type and found the impostor.
is working on a reply...