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

  • Home
  • SEARCH
  • 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 8993285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:09:39+00:00 2026-06-15T23:09:39+00:00

If I am using the MVVM pattern to populate my views, i.e. I am

  • 0

If I am using the MVVM pattern to populate my views, i.e. I am using a View Model in addition to the model classes. The model classes do not talk to the view; the view model populates the view.

In such a scenario, if I need to use data annotations for validation, etc. I need to annotate my view model classes and not my model classes, right?

For e.g. should the [Required] attribute be annotated on:

namespace MyApp.ViewModels
{
    public class Category
    {
        [Required]
        [StringLength(50)]
        public string CategoryName { get; set; }

        [StringLength(255)]
        [AllowHtml]
        public string Description { get; set; }
    }
}

Or should it be this way:

namespace MyApp.Models
{
    public partial class Category
    {
        [Required]
        public virtual string CategoryName
        {
            get;
            set;
        }
    }
}
  • 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-15T23:09:40+00:00Added an answer on June 15, 2026 at 11:09 pm

    Correct, your viewmodel should not use Models(entity) but can contain model properties, example:

    //wrong
    public class Person{
         public string FirstName{get;set;}
         public string LatsName{get;set;}
    }
    
    public class ViewModel{
         public Person Person{get;set;}
    }
    

    this is a better use of viewmodel:

    public class ViewModel{
         public string FirstName{get;set;}
         public string LastName{get;set;}
    }
    

    and yes, your annotations should be on the viewmodel.


    You can set annotations to complex type in the viewmodel too, but please note that complex type should not be a entity/domain class, but a data model class specific only to viewmodel, example:

    public class InsertPerson{
         [Required]
         public string FirstName{get;set;}
    }
    
    public class EditPerson{
         [Required]
         public string Id{get;set;}
    
         [Required]
         public string FirstName{get;set;}
    }
    
    public class ViewModel{
         public InsertPerson insertPerson{get;set;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using the MVVM design pattern and do not want much code in
I am coding a WPF application using MVVM pattern. I don't need to have
I am using MVVM pattern for my app. The model actually runs a set
I'm developing a WPF application using the MVVM pattern and I need to display
We have application have been written in Silverlight using MVVM pattern. We need to
I am using mvvm pattern in WPF application and not using any database. I
I'm writing a Silverlight app using the MVVM pattern. I have a main view
I'm using the MVVM pattern and I have a POCO (in my Model) with
I am using MVVM pattern and I have one DataGrid with a column which
How to get ItemsControl display items selected Item textbox text value using MVVM pattern?

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.