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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:21:08+00:00 2026-05-28T05:21:08+00:00

I’m searching for a good way for managing my view models and especially the

  • 0

I’m searching for a good way for managing my view models and especially the classes used in these view models. I explain below with an example:

Let’s say I would like to display a view which contains a project (title, content, category, …) and below it a list of some related projects (of the same category). I created a view model especially for this view. Here it is:

public class ProjectDetailsViewModel
{
    public ProjectFullViewModel OneProject { get; set; }

    public IEnumerable<ProjectLightViewModel> RelatedProjects { get; set; }

    // Below are the classes used in this view model
    public class ProjectFullViewModel
    {
        public int ProjectID { get; set; }
        public string Title { get; set; }
        public string Slug { get; set; }
        public string Category { get; set; }
        public string Client { get; set; }
        public int Year { get; set; }

        public IEnumerable<Technology> Technologies { get; set; }

        public byte[] ScreenshotData { get; set; }
        public string ScreenshotName { get; set; }
        public int ScreenshotLength { get; set; }
        public string ScreenshotType { get; set; }

        public byte[] BackgroundData { get; set; }
        public string BackgroundName { get; set; }
        public int BackgroundLength { get; set; }
        public string BackgroundType { get; set; }
    }

    public class ProjectLightViewModel
    {
        public int ProjectID { get; set; }
        public string Title { get; set; }
        public string Slug { get; set; }
        public string Category { get; set; }
        public string Client { get; set; }
        public string Year { get; set; }
    }
}

As you can see, all classes used in this view model are contained in it. I think this is easier to keep en eye on what is used. What do you think? Is it a good/bad practice? Some suggestions? I noticed that when we have a lot of view models and classes used we can be a little confused. Don’t blame me, I’m still learning ASP.NET MVC and I would like to make good choices…

Thanks.

  • 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-28T05:21:09+00:00Added an answer on May 28, 2026 at 5:21 am

    I wouldn’t use nested classes for view models. In order to reference them you will have to always specify the base class. That’s could be particularly annoying when writing the mappings between your domain models and view models. If you are afraid of having many files containing your view models you could still place all the dependent view models inside the same .cs file as the parent model.

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a view passing on information from a database: def serve_article(request, id): served_article
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.