Last post Sep 13, 2013 02:19 PM by CPrakash82
Sep 12, 2013 05:36 PM|Jinish|LINK
I have a model with a byte property Image. Then I have an EditViewModel that has a HttpPostedFileBase property Image
When I use Mapper.Map<EditViewModel, EntityModel>(model) it complains about no mapping for HttpPostedFileWrapper and byte.
I am very new to auto mapper, any ideas how to get this working?
Sep 12, 2013 11:14 PM|ignatandrei|LINK
using(var ms= new MemoryStream())
byte data = ms.ToArray();
Sep 12, 2013 11:22 PM|CPrakash82|LINK
You need to define the Automapper Map to map the HttpPostedFileBase with stream or Byte array.
Sep 13, 2013 12:48 PM|Jinish|LINK
I understand this, i could also put this into an extension method. But using this I would have to replicate this code, or call the extension method in my Edit and Create actions. What i was looking for is when I pass my view model to my post action "Create
public ActionResult Create(EditViewModel model)
var model = Mapper.Map<EditViewModel, Model>(model);
Here, how to get this mapping to work seamlessly. I would possibally have to define some kind of conversion rule when Creating the map in the AutoMapperConfig, so I do it once, am i on the right track?
Sep 13, 2013 02:19 PM|CPrakash82|LINK
I would possibally have to define some kind of conversion rule when Creating the map in the AutoMapperConfig, so I do it once, am i on the right track?
Yes, you are right about it and the rule or map does the same, you need to map those property once and after calling Map method it will convert based on the mapping defined.
See - https://github.com/AutoMapper/AutoMapper/wiki/Projection