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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:06:30+00:00 2026-06-05T20:06:30+00:00

I am trying understand ViewModels deeper and I have read many articles and blogs

  • 0

I am trying understand ViewModels deeper and I have read many articles and blogs regarding ViewModel in MVC. In some articles it is said that a Model should not be referenced from ViewModel but in some other articles, using model as a member of viewmodel is suggested.

Lets take an example where I have to create a ViewModel based on a model. I could possible do this in two ways:

1

 public class Car
{
       public int Year {get;set;}
       public string  Make {get;set;}
       //more properties......
}

public class CarViewModel
{
  public CarViewModel(Car model)
  {
    Model = model;
  }

  public Car Model { get; set; }
 //additional view model specific properties
}

Or 2.

public class Car
{
       public int Year {get;set;}
       public string  Make {get;set;}
       //more Car properties......
}

public class CarViewModel
{
       public int Year {get;set;}
       public string  Make {get;set;}
       //more Car properties......

     //additional view model specific properties
}

I am just wondering which one is the correct way of creating a ViewModel. Or is there any other way of doing this altogether?

  • 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-05T20:06:32+00:00Added an answer on June 5, 2026 at 8:06 pm

    I would go for the second approach when the Car model is data persistent say it’s a class created by Entity Framework. In this case I don’t want those models floating around in controllers and views. I will create a view model equivalent to what you have done and use a tool like AutoMapper to map the properties.

    In the first approach the view models acts as wrapper. This you can use in cases where you want to show additional information in a view that is tied with that model. Say you have to add a couple of UI fields and definitely you should not do that in the Car model and you have to create a view model that wraps the Car model and the additional UI fields.

    Basically View Models helps you to keep your business models clean from UI stuff and helps to avoid models that has database stuff floating in views and controllers. So you can use two approaches depend upon the scenarios.

    Hope this answers your question.

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

Sidebar

Related Questions

Just trying to understand that - I have never used it before. How is
I trying to understand Model to ViewModel relation and I keep bumping in the
Trying to understand something that I don't know how to describe because I don't
Trying to understand what Sql Profiler means by emitting sp_reset_connection. I have the following,
Trying to develop using MVVM: I have this Csla.PropertyStatus control that is created in
I'm trying understand how try ... catch construction works in T-SQL. So I've read
I am trying understand how multi queries work in mysqli. But I confess that
Trying to understand the relationship between UIView and CALayer. I read Apple documentation but
I'm trying to understand the HelloScreens sample that comes with Caliburn.Micro . The ShellView.xaml
Trying to understand how you're supposed to read files in python. This is what

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.