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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:17:41+00:00 2026-05-30T12:17:41+00:00

I Have an MVC Project roughly organized like this: Project 1: MVC app (ViewModels,

  • 0

I Have an MVC Project roughly organized like this:

  1. Project 1: MVC app (ViewModels, Controller, Actions, UI-stuff)
  2. Project 2: Domain Model (Domain Classes, behavior, Data Access (Persitance layer, Repositories)

My question is where to do mapping and data access (how to organize the code).

By definition (as I understand it) the controller should map the request to the right view and be as skinny as possible.

I use Automapper on the basic mapping, and I do it in the controller, but for more complex mapping I find it easier to do the mapping myself.

I have mainly two places to put the code for this:

  1. In the controller:

This can easily get quite messy, specially if I need to get information from several repositories, create select lists and so on.

  1. In the ViewModel:

This feels better, but I don’t like instansiating Repositories and UnitOfWork in the model. Don’t know if that belong there.

Right now I’m doing something in between:

I let the ViewModel take the needed repositories as contructor
parameters, and I do the mapping there. I instansiate the
Repositories/UnitOfWork in the controller and pass it in. The good
thing is that I can use an Interface for the repositories so the
ViewModel doesn’t need to care about implementation.

However, in examples on the web I always see all this code in the controller so that makes me wonder – what is the right way to do it?

  • 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-30T12:17:41+00:00Added an answer on May 30, 2026 at 12:17 pm

    In order to do it in the ViewModel, that would mean your viewmodel has to understand your other object. That’s not good. The ViewModel should be as dumb about external dependencies as possible.

    You should be doing the mapping in the controller.

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

Sidebar

Related Questions

I have an MVC solution setup like this, with three 'projects'. Web (MVC Project,
I have an MVC project that I would like to write in .NET 4.0
I have an ASPNET MVC 2 project. When I use <%= Html.TextBoxFor(model => model.Login)
I have this sample MVC project using jQuery grid. There is only one problem
Azure web role (MVC 3 project) wont' start with Twilio controller class I have
So I have a MVC app and in another project I have a normal
I have MVC project on Windows Azure. This project has WebRole with method OnStart.
Good time of a day! I have a MVC project with query in controller:
I Have a MVC Project with a Model named Contact, in create view how
I have a spring mvc project set up like so: <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param>

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.