Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Edit is not saving then changes in MVC4 Automapper
Below is my code..
C#
public ActionResult Edit(int id, User userDetails)//
        {
            try
            {
               var dbContext = new MyDBDataContext();
                Mapper.CreateMap<learningmvc.user,>();             
                var user = Mapper.Map<learningmvc.user,learningmvc.models.user>(userDetails);               
                  dbContext.SubmitChanges();
                  return RedirectToAction("Index");
                  
            }
            catch
            {
                return View();
            }
            
        }
Posted
Comments
Bhushan Patki 5-Dec-13 7:09am    
Can you plz trace the ecxeption or put after try block(If(model.Isvalid)), Because may be ur model state is invalid
[no name] 13-Dec-13 15:51pm    
before submit change, how did you attach your mapped user to dbcontext. if you paste your exact code then it would be more clear to understand.

1 solution

Hi,
Your CreateMap is missing destination class. Also please check the names of properties are in sync in both the classes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900