Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm not able to create a partial class to extend a generated model. Can anyone help?
I'm in Dll mode
I create a class called Startpage.cs and put it in App_data\Models (Not inluded in the projekt)
It looks like this:
namespace Umbraco.Web.PublishedContentModels { public partial class Startpage { public string TestProp { get { return "TestProp"; } } } }
In the template i write this:
<p>@Model.Content.TestProp</p>
Not working...
Hi Ken,
As I know these classes are generated - you can't create them.
If you want to return a custom model for Umbraco page, look here - https://github.com/kgiszewski/LearnUmbraco7/blob/master/Chapter%2006%20-%20Surface,%20WebAPI%20and%20RenderMVC%20Controllers/01%20-%20RenderMVC%20Controllers.md
And ask, ask, ask !!! :)
Thanks,
Alex
Hi, according this text it should be possible
"Because a model is generated as a partial class, it is possible to extend it, eg adding a property, by dropping the following code in a MyDocument.cs file:"
from this page
https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Understand-And-Extend
Thanks, Ken, didn't use it like that.
@Ken - did you manage to resolve this at all? Am encountering the same problem with my v7.5.9 installation, running ModelsBuilder in Dll mode.
I've had this working in previous versions of Umbraco but doesn't seem to want to work in my first 7.9 site, is this a breaking change?
I do this all the time (Including 7.9.x), but I target the generated classes into a seperate assembly, and then add partial classes there.
The big thing is that the namespace needs to be the same in both classes for it to work correctly.
Ok yes thank you I see that's the answer. How do you define that? Which mode is that? How do you say what assembly you way it to be in?
Hi John,
you can define the namespace that models builder is using for the generated classes:
Umbraco.ModelsBuilder.ModelsNamespace (string, default is Umbraco.Web.PublishedContentModels) specifies the generated models namespace.
Then you can use that namespace also on your partial classes and it should pick it up.
Regards David
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Extend Model using partial class
I'm not able to create a partial class to extend a generated model. Can anyone help?
I'm in Dll mode
I create a class called Startpage.cs and put it in App_data\Models (Not inluded in the projekt)
It looks like this:
In the template i write this:
Not working...
Hi Ken,
As I know these classes are generated - you can't create them.
If you want to return a custom model for Umbraco page, look here - https://github.com/kgiszewski/LearnUmbraco7/blob/master/Chapter%2006%20-%20Surface,%20WebAPI%20and%20RenderMVC%20Controllers/01%20-%20RenderMVC%20Controllers.md
And ask, ask, ask !!! :)
Thanks,
Alex
Hi, according this text it should be possible
"Because a model is generated as a partial class, it is possible to extend it, eg adding a property, by dropping the following code in a MyDocument.cs file:"
from this page
https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Understand-And-Extend
Thanks, Ken, didn't use it like that.
@Ken - did you manage to resolve this at all? Am encountering the same problem with my v7.5.9 installation, running ModelsBuilder in Dll mode.
I've had this working in previous versions of Umbraco but doesn't seem to want to work in my first 7.9 site, is this a breaking change?
I do this all the time (Including 7.9.x), but I target the generated classes into a seperate assembly, and then add partial classes there.
The big thing is that the namespace needs to be the same in both classes for it to work correctly.
Ok yes thank you I see that's the answer. How do you define that? Which mode is that? How do you say what assembly you way it to be in?
Hi John,
you can define the namespace that models builder is using for the generated classes:
Then you can use that namespace also on your partial classes and it should pick it up.
Regards David
is working on a reply...