Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7992923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:42:30+00:00 2026-06-04T13:42:30+00:00

in my solution I have an ASP.NET MVC3 project, and a WCF project that

  • 0

in my solution I have an ASP.NET MVC3 project, and a WCF project that works with a database.
I use entity framework self tracking and AutoMapper to map objects.

My question is: how i can use AutoMapper with Post Action like crate and delete and Edit methods

i see this Questions but not help me
this give me an error argument type '...' is not assignable to parameter type '...'

      [HttpPost]
      public ActionResult Create(MUser muser)
      {
        if (ModelState.IsValid)
        {
            Mapper.CreateMap<User, MUser>();
            var user = Mapper.Map<User, MUser>(muser);
            _proxy.SaveUser(user);
            return RedirectToAction("Index");

        }
        return View(muser);
      }

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:42:32+00:00Added an answer on June 4, 2026 at 1:42 pm

    You shouldn’t place the Mapper.CreateMap in your controller, you need to perform that action only once, so create a bootstrapper or something like that and call it from your application start method.

    I think that’s where your error comes from: you can create a mapping only once.

    Oh, and you’re defining the wrong types. You aren’t trying to convert a User to a MUser, but you’re doing it the other way around, so it should be:

    Mapper.CreateMap<MUser, User>();
    Mapper.Map<MUser, User>(muser);
    

    Example of how to do this:

    public class MvcApplication : HttpApplication
    {
        // some methods
    
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
    
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
    
            MappingsBootstrapper.Initialize(); // call the bootstrap class that I created
        }
    }
    

    Then I’ve got a project called ‘Mappings’ and it contains the bootstrap class and some ‘configuration’ classes (just like Entity Framework has EntityTypeConfiguration classes and Ninject has NinjectModules):

    public static class MappingsBootstrapper
    {
        public static void Initialize()
        {
            new UserMappings();
            new BookcaseItemMappings();
        }
    }
    

    And the mappings:

    class UserMappings
    {
        public UserMappings()
        {
            Mapper.CreateMap<User, UserSetupViewModel>();
            Mapper.CreateMap<UserSetupViewModel, User>();
        }
    }
    
    class BookcaseItemMappings
    {
        public BookcaseItemMappings()
        {
            Mapper.CreateMap<NewBookViewModel, BookcaseItem>().ForMember(x => x.BookId, opt => opt.Ignore());
            Mapper.CreateMap<BookcaseItem, BookcaseItemViewModel>()
                .ForMember(x => x.Title, opt => opt.MapFrom(src => src.Book.Title))
                .ForMember(x => x.Authors, opt => opt.MapFrom(src => src.Book.Authors.Select(x => x.Name).Aggregate((i, j) => i + ", " + j)))
                .ForMember(x => x.Identifiers, opt => opt.MapFrom(src => (!string.IsNullOrEmpty(src.Book.Isbn10) ? ("ISBN10: " + src.Book.Isbn10 + "\r\n") : string.Empty) +
                                                                         (!string.IsNullOrEmpty(src.Book.Isbn13) ? ("ISBN13: " + src.Book.Isbn13) : string.Empty)))
                .ForMember(x => x.Pages, opt => opt.MapFrom(src => src.Book.Pages))
                .ForMember(x => x.ImageUri, opt => opt.MapFrom(src => src.Book.ThumbnailUriSmall));
        }
    }
    

    You can do it any way you like, you could just place all the mappings in your Application_Start() method, but I found this to be a clean and maintainable way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my solution I have an ASP.NET MVC3 project, and a WCF project that
I have ASP.NET MVC3 project and I am writing some extension methods that returns
We have an ASP.Net MVC solution built in VS2008 and TFS2008. We use TFS
I have a multi-project ASP.NET + C# solution. I was planning on writing a
I've been fiddling with some ASP.NET MVC3 solution structures and I have settled on
So I have a VS 2010 solution containing one ASP.NET MVC 3 project and
I have a 3 tier ASP.NET MVC 3 project that has a data layer,
I am currently working on an ASP.NET MVC3 project in Visual Studio. I have
I'm working on a asp.net mvc3 solution that has 3 projects Data, Service, and
I have solution with two projects. ASP.NET MVC3 Class library In class library I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.