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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:06:59+00:00 2026-05-11T21:06:59+00:00

I have been learning ASP.NET MVC for a few months. I have learned about

  • 0

I have been learning ASP.NET MVC for a few months. I have learned about views and controllers and models and stuff. To design a view, we always need a model.
Usually a model is a just a class which we fill with data and pass to a view. I have a question here: Should a model itself do some calculation, or should it just be dumb?

For example, I have a site where I load Books by Users. My model class is as follows:

public class FormViewModel
{
  public User MyUser {get; set;}
  public Books UserBooks {get; set;}

  //Constructor here. 
  public FormViewModel(User _user, Books _userBooks)
  {
    this.MyUser=_user;
    this.UserBooks=_userBooks;
  }
}

This class doesn’t do anything — it’s just a template. Now if I modify the code as follows:

public class FormViewModel
{
  public User MyUser {get; set;}
  public Books UserBooks {get; set;}

  //Constructor here. 
  public FormViewModel(User _user)
  {
    this.MyUser=_user;
    this.UserBooks=_user.GetBooks();
  }
}

which Books are collected depends on which User has been selected. Now it’s much easier to work with.

I just want to know what is a good approach according to MVC patterns and practices.

  • 1 1 Answer
  • 1 View
  • 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-11T21:06:59+00:00Added an answer on May 11, 2026 at 9:06 pm

    You can do it a couple of ways, but I’d say the easiest way would be to pass in the reference identifier for the user which you are trying to access through to the controller action (as below) and let it do all the data access calls.

    public void GetUserAndDetails(Guid userId) { ... }
    

    Then in this controller action you can look up the user details and the books for this user, set the properties on the view model instance and return it to the view to access.

    FormViewModel model = new FormViewModel();
    model.MyUser = GetUser(userId);
    model.UserBooks = GetUserBooks(userId);
    return View(model);
    

    This way the view remains dumb (which it should be) and the model is relatively simple. This also helps with testing purposes.

    Hope this helps.

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

Sidebar

Related Questions

I have been learning ASP.NET MVC in the last few months and I think
I'm working on an ASP.Net MVC project and have been learning a few little
I been reading on asp.net mvc learning site about JavaScript injection and man it
I have been learning to develop websites using ASP.NET MVC 2 for work... and
I have been learning C# for the past few days for use with ASP.NET
I've been working with ASP.NET MVC for the last few weeks, learning as I
I have been learning ASP.NET MVC recently and everything is going well apart from
Have been learning ASP.NET (using C#) over the past few days. I have made
Im learning asp.net mvc and have been investigating jquery and the like. As yet
I am learning asp.net MVC, as I have been using the sqlconnection, sqlcommands etc

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.