3

According to the DXA 1.1 documentation it should be possible to create custom Media Items.

I have created an EntityModel with a public MediaItem Media { get; set; } property (the property could be used for multiple Media Item types). Also created a custom Image EntityModel. When I use a core Image mm component the image is mapped correctly, however when I use a mm component based on my custom Image schema, I am getting the following error:

Unable to map field 'media' to property of type 'Sdl.Web.Common.Models.MediaItem'.

I am just not sure how to configure DXA for it to use the custom Image EntityModel. What am I missing here?

1 Answer 1

4

If your model has a property with an abstract type (e.g. MediaItem) and hence you expect the model mapping to instantiate a concrete subclass of that type, you have to ensure there is a semantic mapping on type-level between your CM Schema and your View Model type.

Ensure your View Model type is registered (with or without associated View) and maps to your CM Schema based on name/title (default mapping) or through SemanticEntity attribute. For example, see: https://github.com/sdl/dxa-modules/blob/master/webapp-net/MediaManager/Models/MediaManagerDistribution.cs

If no semantic mapping can be resolved, a warning will be logged and the model mapping will fallback to the type of the property, which will result in the mentioned error if the property type is abstract.

So: set the log level to WARNING (or DEBUG) and check whether you see such a warning. Then check the semantic mapping of your View Model type.

1
  • Rick's answer is correct. However when your custom Media Item has the same name as a core item (in my case Image schema & model), there are some additional steps to take. By default DXA will find multiple models that could be mapped based on schema name & core and schema.org vocabularies. The solution then is to create a custom vocabulary in the global appdata and associate it with the custom Media Item schema. Finally adding the corresponding semantic mapping to the model will do the trick. Oct 8, 2015 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.