How do you ignore/persist values in MVC when your view-model doesn't have as many fields as your domain model?

五迷三道 提交于 2019-12-05 07:43:05

The asp.net mvc DefaultModelBinder is extensible, and you can override it to create your own binding schema. But this will involve more work than two "hidden Input fields", which , in my point of view, is not that gross.

mxmissile

You can tell Automapper to ignore the 2 properties:

Mapper.CreateMap<Source, Destination>()
.ForMember(dest => dest.SomeValuefff, opt => opt.Ignore());

Possible related question.

Can you use the AutoMapper.Map overload that also accepts TEntity?!

entity = Mapper.Map(viewmodel, entity);

As long as you do not have the properties on your viewmodel, it won't change the values on your entity. It takes the entity being passed in and applies only the properties from the viewmodel back to the entity.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!