I have model with property:
public class MyModel{
public SelectList PropertyTypeList { get; set; }
}
And I have ValueResolver
public class MyPropertyValueResolver : ValueResolver<ProductProperty, SelectList>
{
protected override SelectList ResolveCore(ProductProperty source)
{
myList = .......;
return new SelectList(myList, "Value", "Text");
}
}
Then I configure mapping
Mapper.CreateMap<Source, Destination>()
.ForMember(s => s.PropertyTypeList, opt => opt.ResolveUsing<MyPropertyValueResolver>());
But it says me that
Type 'System.Web.Mvc.SelectList' does not have a default constructor
What I should to do to make it work?
Rather than automapping to a SelectList, have you considered automapping to a simple Array, and then using a Get-only property to wrap this as a SelectList?
This answer describes the approach.
Also, from the same SO question, there is the ConstructedBy idea, as well as a way to use MapFrom
to do this directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With