2

I am trying to map a Component link field to a dynamic type Module and I am getting this error:

Unable to map field 'dynamic field' to property of type 'System.Object'.
Unable to cast object of type 'System.Object' to type 'Sdl.Web.Common.Models.ViewModel'.

Class:

public class aModel : EntityModel
{
    public List<dynamic> aField { get; set; }
}

Does DXA support dynamic type mapping? Thanks

4

No, it doesn't; DXA uses Strongly Typed View Models. The supported View Model property types depend on the CM field type you are mapping to.

In case of a CM Component Link field, you can map it to a property of type EntityModel (so any kind of embedded Entity Model), but you can't make it more loosely typed than that.

2

If you allow multiple schemas on a component link field, I would recommend think about the schema design up front so you can create a base view model class. Then you can avoid using dynamic type. It also means you will quite likely be able to reuse partial views.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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