Using AutoMapper in the Edit action method in an MVC3 application

后端 未结 1 1422
时光说笑
时光说笑 2021-02-08 11:46

Here is my controller code, which works 100% as I need it to. However the POST method isn\'t using the AutoMapper and that is not OK. How can I use AutoMapper in this action met

相关标签:
1条回答
  • 2021-02-08 12:00

    I think you just do

     Product product = _productRepository.FindProduct(model.ProductId);
     Mapper.Map(model, product);
     _productRepository.SaveChanges();
    

    you may also want to check that you have a non null product first, and also that user is allowed to change that product....

    0 讨论(0)
提交回复
热议问题