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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:32:19+00:00 2026-06-17T07:32:19+00:00

In my project i have one viewmodel per domainmodel and reuse this viewmodel in

  • 0

In my project i have one viewmodel per domainmodel and reuse this viewmodel in more then one view.

Example of one viewmodel

 public class ProductViewModel
    {
        public int ProductId { get; set; }
        public int ProductGroupId { get; set; }
        public bool IsLinkedToErp { get; set; }

        [Required(AllowEmptyStrings = false)]
        [Display(Name = "Standard")]
        public bool IsDefault { get; set; }

        [MaxLength(50)]
        [Required(AllowEmptyStrings = false)]
        [Display(Name = "Artnr")]
        public string ArtNo { get; set; }

        [MaxLength(255)]
        [Required(AllowEmptyStrings = false)]
        [Display(Name = "Beskrivning")]
        public string Description { get; set; }

        [MaxLength(255)]
        [Required(AllowEmptyStrings = false)]
        [Display(Name = "Specifikation")]
        public string Specification { get; set; }

        [MaxLength(5)]
        [Required(AllowEmptyStrings = false)]
        [Display(Name = "Enhet")]
        public string Unit { get; set; }

        [MaxLength(4)]
        [Required(AllowEmptyStrings = false)]
        [Display(Name = "Konto")]
        public string Account { get; set; }

        [Required(AllowEmptyStrings = false)]
        [Display(Name = "Netto")]
        public decimal NetPrice { get; set; }

        public string ChUser { get; set; }

        public DateTime ChTime { get; set; }

        public string GetUpdatedDate
        {
            get { return String.Format("{0:d}", ChTime); }
        }

        public string GetNetPrice
        {
            get { return String.Format("{0:0.00}", NetPrice); }
        }
    }

All my views in ProductController reuse this ViewModel.
For List, Add and Edit. But in list i only use a few of all properties.

Then i using Automapper to map to Domain and vice versa.

Now I’m wondering if anyone has experience of this. Do you think I will have problems using this solution as the project grows?

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

    I would consider splitting out the ListViewModel and the Add/Edit view models if only because you are potentially populating and sending more data than you really need to your view.

    By leveraging from inheritance, you could quickly make two classes that contain only the data that you need for your view. Based on your example, I would consider the following:

    public class ProductListViewModel{
        public IEnumerable<ProductListModel> products {get;set;}
    
        public string SomeOtherPotentialVariableForProductList {get;set;}
    }
    
    public class ProductListModel{
        public int ProductId { get; set; }
    
        public int ProductGroupId { get; set; }
    
        [MaxLength(255)]
        [Required(AllowEmptyStrings = false)]
        [Display(Name = "Beskrivning")]
        public string Description { get; set; }
    
        [Required(AllowEmptyStrings = false)]
        [Display(Name = "Netto")]
        public decimal NetPrice { get; set; }
    }
    
    public class ProductViewModel : ProductListModel
        {
    
            public bool IsLinkedToErp { get; set; }
    
            [Required(AllowEmptyStrings = false)]
            [Display(Name = "Standard")]
            public bool IsDefault { get; set; }
    
            [MaxLength(50)]
            [Required(AllowEmptyStrings = false)]
            [Display(Name = "Artnr")]
            public string ArtNo { get; set; }
    
            [MaxLength(255)]
            [Required(AllowEmptyStrings = false)]
            [Display(Name = "Specifikation")]
            public string Specification { get; set; }
    
            [MaxLength(5)]
            [Required(AllowEmptyStrings = false)]
            [Display(Name = "Enhet")]
            public string Unit { get; set; }
    
            [MaxLength(4)]
            [Required(AllowEmptyStrings = false)]
            [Display(Name = "Konto")]
            public string Account { get; set; }
    
            public string ChUser { get; set; }
    
            public DateTime ChTime { get; set; }
    
            public string GetUpdatedDate
            {
                get { return String.Format("{0:d}", ChTime); }
            }
    

    This accomplishes a few things.

    1. You are only sending the data that is required for the view.
    2. If you find yourself needing more information for the list view that may not be directly related to a product, you can quickly add that property.
    3. By inheriting from the ProductListModel, you are not repeating yourself within your code.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it a better idea to have a single ViewModel per view or one
in my project i have one registration form which is developed in C#.net.to this
I'm trying to pass my View an instance of the following ViewModel: public class
I have the following entity model: public class Project { [Key] public int ProjectID
In my project I have one table with 24*6*300 cells on one page (it's
I have one project inside that I have SqlServerFunctions in test.cs file. code: [Microsoft.SqlServer.Server.SqlFunction]
I have one project with is developed in Php and javascript. How to open
I have one project which has RIAService with entity framework that is referenced to
I currently have one project that currently contains multiple packages. These packages make up
Let's say I have one project with the following POM: <groupId>com.mine</groupId> <artifactId>coreJar</artifactId> <packaging>jar</packaging> <version>0.0.1-SNAPSHOT</version>

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.