e.g.: var mediaItem = Umbraco.TypedMedia(1234).OfType<Image>();
How do I achieve this functionality with custom media types?
Let's say we create a media type "MyImage" in the MediaTypes root. This media type inherits tabs via Compositions from Image and has another prop called "Title".
var mediaItem = Umbraco.TypedMedia(1234).OfType<MyImage>(); leads to an error.
Thanks for your help. I switched from PureLive to Dll, but the error remained. BUT: I examined the generated .cs files for the models. And I found out, that it was simply a missspelling in upper in lowercase.
I named the media type MYImage
The automatically generated Alias was created as mYImage
And in the .cs file the class name is MYimage
I don't know if there's any technical reason why this has to be so. But for me as a user and programmer it is rather cumbersome to deal with three different spellings :-(
Alias always start with lowercase and classes always start with uppercase, although if you had used dll mode, rebuilt the model in the developer section then you should have had Intellisense removing the typo factor
I really got the rule for the alias pretty quick: "Take my name and lower the first letter".
The rule for the class name is somewhat trickier: Take the alias name and upper the first letter. Check all other letters and if there a multiple upper letters in a row, lower all except the first.
Umbraco.TypedMedia OfType with custom MediaTypes
Hi,
As described here (https://our.umbraco.com/documentation/Getting-Started/Design/Rendering-Media/) you can use
.OfType
to convert to distinct media type (such asImage
) in order to use a strongly typed object and its properties.e.g.:
var mediaItem = Umbraco.TypedMedia(1234).OfType<Image>();
How do I achieve this functionality with custom media types?
Let's say we create a media type "MyImage" in the MediaTypes root. This media type inherits tabs via Compositions from Image and has another prop called "Title".
var mediaItem = Umbraco.TypedMedia(1234).OfType<MyImage>();
leads to an error.Stephan
Can anybody help?
What’s the error you are getting?
I assume you’re using PureLive model mode so the objects are created at runtime, have you tried using Dll model mode to see if that works?
Checkout https://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/
Hi Jamie,
Thanks for your help. I switched from PureLive to Dll, but the error remained. BUT: I examined the generated .cs files for the models. And I found out, that it was simply a missspelling in upper in lowercase.
I named the media type MYImage
The automatically generated Alias was created as mYImage
And in the .cs file the class name is MYimage
I don't know if there's any technical reason why this has to be so. But for me as a user and programmer it is rather cumbersome to deal with three different spellings :-(
Stephan
Alias always start with lowercase and classes always start with uppercase, although if you had used dll mode, rebuilt the model in the developer section then you should have had Intellisense removing the typo factor
Hi,
I really got the rule for the alias pretty quick: "Take my name and lower the first letter".
The rule for the class name is somewhat trickier: Take the alias name and upper the first letter. Check all other letters and if there a multiple upper letters in a row, lower all except the first.
e.g.: MYFooBAR (Name) -> mYFooBAR (Alias) -> MYfooBar (Class name)
Stephan
P.S.: I cannot use VS because the site is directly on the server and I can only access it via RD.
is working on a reply...