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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:20:23+00:00 2026-06-17T00:20:23+00:00

I have read several articles, tutorials and blog posts about the MVVM pattern. However

  • 0

I have read several articles, tutorials and blog posts about the MVVM pattern. However there is one thing I don’t understand. Taking the three “layers”:

  • Model
  • View
  • View Model

As far as I have understood MVVM the model contains the “raw” data, e.g. a name and address in case of a Student class. The view model exposes properties to the view which represent data of the model.

Example for a property in the view model

public string Name {
 get { return model.Name; }
 set { model.Name = value; }
}

Example for the model

private string name;

public string Name {
 get { return name; }
 set { name = value; }
}

This might sound a bit stupid but doesn’t this create a redundancy? Why do I have to keep the name in the model and in the view model? Why should one not handle the name on the view model completely?

  • 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-17T00:20:24+00:00Added an answer on June 17, 2026 at 12:20 am

    In such a simple example, this answer would be yes (it is unreasonably redundant). But, presumably, a page will contain more than just a single Model object. You may have the page state as well as multiple other Model objects which must all be tracked. This is done in the ViewModel.

    For example, you may have additional information about the logged in user displayed in a status bar, as well as a service running to detect changes to a text file.

    You may also have a form for editing the Student object. If you intend to validate those changes, then you wouldn’t want to directly edit the Student object until after the modifications have been verified. The ViewModel can act as a temporary storage location in such a case.

    Note on the above: It is not uncommon for validation to occur in the Model, but even then you will probably want the user to be able to enter invalid values while in the process of editing a form. For example, if your Model does not allow a zero-length value in a field, you still want to enable your user to delete the value, move to another field (say, for example, to copy it) then return to the field and finish editing (paste). If you are tied directly to the Model, then your validation logic may not handle this “in-between”, “not-yet-finished” state as you’d like. For example, you might not want to accost your user with validation errors until they’ve finished and clicked ‘Save’.

    You will also probably have Command objects in the ViewModel to handle button clicks and the like. These would be domain-specific objects that would be useless in a Model.

    ViewModels are also useful when you need to filter or somehow temporarily “modify” Model objects to get something useful on the screen. For example, you may want to display a list of all the Users in a system along with a real-time list of the top ten performers among them (updated every 10 seconds). Or you may want to show a list of Reports and a graph showing the overall usage rate, etc. Filtering, sorting and customizing that data would take place within the ViewModel.

    The Model, on the other hand, is typically as pure as possible. Ideally, you want only POCOs that (usually) model exactly what’s in your persistent storage (database, or what have you). If your persistent storage has FirstName and LastName fields, then so would your Model. Only in your ViewModel would you combine them to get a Name field (either “First Last” or “Last, First” depending on the View’s needs).

    For example:

    namespace Model
    {
        public class Student
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
        }
    
        public class Class
        {
            public string Name { get; set; }
            public float Score { get; set; }
        }
    }
    
    namespace ViewModel
    {
        public class EditStudentRecordViewModel
        {
            private Model.Student _student;
            private IEnumerable<Model.Class> _studentClasses;
    
            /* Bind your View to these fields: */
            public string FullName
            {
                return _student.LastName + ", " + _student.FirstName;
            }
            public string FirstName { get; set; }
            public string LastName { get; set; }
    
            public IEnumerable<Model.Class> PassingClasses
            {
                get
                {
                    return _studentClasses.Where( c => c.Score >= 78 );
                }
            }
    
            public IEnumerable<Model.Class> FailingClasses
            {
                get
                {
                    return _studentClasses.Where( c => c.Score < 78 );
                }
            }
    
            public void Save()
            {
                List<string> l_validationErrors = new List<string>();
                if ( string.IsNullOrEmpty( this.FirstName ) )
                    l_validationErrors.Add( "First Name must not be empty." );
                if ( string.IsNullOrEmpty( this.LastName ) )
                    l_validationErrors.Add( "Last Name must not be empty." );
    
                if ( l_validationErrors.Any() )
                    return;
    
                _student.FirstName = this.FirstName;
                _student.LastName = this.LastName;
                Model.Utilities.SaveStudent( _student );
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read several articles and tutorials on the MVVM pattern but there is
I have read several articles and several stackoverflow.com posts about expression tree. It is
I have read several posts about the configuration manager in VS2010 (or before) but
I have read several articles on the topic as this one and implemented most
I have lately read several articles and questions about Model Binding and Validation in
I feel bad about not getting this. But, although I have read several articles
I have read many articles, discussions and tutorials about using utf-8 charset in mysql.
I have read several articles about UITableView, including the official doc and some on
I have read several articles and questions on concept of foreign key vs independent
I have read through several articles which are alternatives to using setpixel/getpixel but 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.