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 6640729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:42:24+00:00 2026-05-25T23:42:24+00:00

I am using ASP.NET MVC 3 and AutoMapper . In my category controller I

  • 0

I am using ASP.NET MVC 3 and AutoMapper.

In my category controller I return a list of categories and I want to map each category to a category view model which is used in my grid. I have my own mapper class method that accepts the source, source type and destination type and then does the mapping of single objects. How would I add and additional method so that I can map lists?

For example, if I want to map a single category to my category edit view model then the following mapping will be used:

Mapper.CreateMap<CategoryCreateViewModel, Category>();

In my controller I would map the 2 like this:

Category category = (Category)categoryMapper.Map(viewModel, typeof(CategoryCreateViewModel), typeof(Category));

This is what my mapping method looks like:

public class CategoryMapper : ICategoryMapper
{
     static CategoryMapper()
     {
          Mapper.CreateMap<Category, CategoryCreateViewModel>();
          Mapper.CreateMap<Category, CategoryViewModel>();
          Mapper.CreateMap<CategoryCreateViewModel, Category>();
     }

     public object Map(object source, Type sourceType, Type destinationType)
     {
          return Mapper.Map(source, sourceType, destinationType);
     }

     // I have been trying to get this right but not working
     //public object Map(object source, IEnumerable<Type> sourceType, IEnumerable<Type> destinationType)
     //{
     //     return Mapper.Map(sourceType, destinationType);
     //}
}

I want to add another method where I can map lists. How would I do this?

  • 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-05-25T23:42:25+00:00Added an answer on May 25, 2026 at 11:42 pm

    I wanted to use my IMapper methods like I mentioned above. With the help of Darin Dimitrov I got this to work. Here is my controller code:

    public ActionResult JsonGetParentCategoryList()
    {
         IEnumerable<Category> categoryList = categoryService.GetAll();
    
         // Mapping
         IEnumerable<CategoryViewModel> viewModelList = (IEnumerable<CategoryViewModel>)
              categoryMapper.Map(
                   categoryList,
                   typeof(IEnumerable<Category>),
                   typeof(IEnumerable<CategoryViewModel>)
         );
    
         JsonEncapsulatorDto<CategoryViewModel> data = new JsonEncapsulatorDto<CategoryViewModel>
         {
              DataResultSet = viewModelList
         };
    
         return Json(data, JsonRequestBehavior.AllowGet);
    }
    

    It works with my current IMapper Map method.

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

Sidebar

Related Questions

I'm using AutoMapper to map domain entities to view models in an Asp.Net MVC
The service layer of my ASP.NET MVC 3 application uses AutoMapper to map view
In my ASP.NET MVC 2 (RC) project - I'm using AutoMapper to map between
I am using AutoMapper in my ASP.NET MVC website to map my database objects
Using Asp.net MVC, I have one view that's strongly bind to List , and
Using ASP.NET MVC when I create my model, then a controller based on the
Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,
I am using AutoMapper in my project along with, NHibernate and ASP.NET MVC 2.
Using ASP.NET MVC & Spark, I have a view that is listing a number
I am using ASP.Net MVC with ADO.Net Entity Data Model. When I use ToList()

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.