I've followed those steps and extended a class called HomePage:
namespace Umbraco.Cms.Web.Common.PublishedModels
{
public partial class Homepage
{
public int MyProperty { get; set; }
}
}
But I am constantly getting this error:
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.CompilationFailedException: 'One or more compilation failures occurred:
x5hui2un.yt1(66,94): error CS0433: The type 'Homepage' exists in both 'ModelsGeneratedAssembly, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null' and 'Umbraco9Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null''
Could anyone be so kind as to shed some light here? I can't pinpoint what I may be doing wrong.
You need to have your generated models, and your partial classes in the same project.
What are your models builder settings? You can set them in appsettings (https://our.umbraco.com/documentation/Reference/Templating/Modelsbuilder/configuration)
Make sure your models directory is in the project where you extend the models.
That was the missing link. Nowhere in the documentation that information is present. I was using the default settings (InMemoryAuto) and never remembered or realized that the class would be outside the project.
I changed it to SourceCodeAuto, updated the models and it's now working.
Problem while extending model
Hello everyone.
I've been using Umbraco, mostly on version 7. I started getting my feet wet on v9 and some concepts are new to me, of course.
I have checked out how to extend models at the official documentation: https://our.umbraco.com/documentation/reference/templating/modelsbuilder/Understand-And-Extend
I've followed those steps and extended a class called HomePage:
But I am constantly getting this error:
Could anyone be so kind as to shed some light here? I can't pinpoint what I may be doing wrong.
Thank you very much in advance.
You need to have your generated models, and your partial classes in the same project.
What are your models builder settings? You can set them in appsettings (https://our.umbraco.com/documentation/Reference/Templating/Modelsbuilder/configuration)
Make sure your models directory is in the project where you extend the models.
That was the missing link. Nowhere in the documentation that information is present. I was using the default settings (InMemoryAuto) and never remembered or realized that the class would be outside the project.
I changed it to SourceCodeAuto, updated the models and it's now working.
Thank you very much, Søren.
is working on a reply...