Try our conversational search powered by Generative AI!

Type 'Alloy.Models.lmageFile' could not be mapped to a PropertyDefinitionType


I've been tampering with a fresh template of the Alloy installation page for some time now, and one thing, that has been bugging me for a while now, is the ImageFile mapping. The whole site gives an error that says the ImageFile couldn't be mapped to a PropertyDefinitionType as written above.

The problem occurs when I define an ImageFile property in a block or page like this

public class ImageBlock : BlockData
  [Display(GroupName = SystemTabNames.Content)]
  public virtual ImageFile Image { get; set; }

This approach breaks the whole site by telling me that the ImageFile could not be mapped to a property. The Alloy template has an ImageFileController, which maps the ImageFile to an ImageViewModel

public override ActionResult Index(ImageFile currentContent)
   var model = new ImageViewModel
     Url = _urlResolver.GetUrl(currentContent.ContentLink),
     Name = currentContent.Name,
     Copyright = currentContent.Copyright

   return PartialView(model);

But this does not offer any comfort at all. Nowhere in the Alloy template is the ImageFile property being used, which does not make any sense.

What was the idea of this? What am I missing in order to use an ImageFile property in my block and page types?

Jun 03, 2019 14:11

Hi Yusof,

If I understand you correctly, then the important thing to note is that in Episerver images are IContentjust like blocks, pages, videos, forms etc. You therefore interact and work with images in the same way as other content.

If you haven't already, I'd definitely recommend you look at the Content section in the documentation, especially Media type and templates. The following summary is taken directly from there:

  • A media type defines a set of properties.
  • A media is an instance of the .NET class that defined the media type.
  • When an editor creates/uploads media, values are assigned to the properties defined by the media type.
  • When an instance of media is requested by a visitor, the default media handler sends the binary data to the visitor.

So, the ImageFile in Alloy is a media type: a programmatic definition of media (in this case specifically an image) which includes some additional properties (e.g. AltTag). There is more about specialized media types (like images) in the documentation I linked above.

What you want to use on your block is not an image media type but an editor uploaded image media instance. To do this, you want the editor to be able to specify a reference/link to that uploaded image content, unsuprisingly called a ContentReference. Again, this is covered in detail in the documentation (see Linking to other content).

Simply put, your block should look like this:

public class ImageBlock : BlockData
  [Display(GroupName = SystemTabNames.Content)]
  public virtual ContentReference Image { get; set; }

There are already plenty of examples of this in Alloy, look at the JumbotronBlock for a start. From here, should you need to, you can get that content from the database using the IContentLoader or IContentRepository.

Hoping that gives you a start, it's honestly possible to write a lot about this.


Edited, Jun 06, 2019 23:36
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.