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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:11:32+00:00 2026-05-24T08:11:32+00:00

In the past, when writing my code, I always assumed that the model should

  • 0

In the past, when writing my code, I always assumed that the model should just consist of a bunch of auto properties populated by the controller. But I recently came across code like this and want to know if it’s valid for MVC:

public class SomeModel
{

    public BusinessInfo BusinessInfo { get; set; }
    public IList<BusinessService> BusinessServices { get; set; }
    public IList<BusinessHour> BusinessHours { get; set; }


    public BusinessService GetBusinessServiceByServiceId(int serviceId)
    {
        return BusinessServices.FirstOrDefault(businessService =>
                        businessService.Service.ServiceId == serviceId);
    }
} 

Is having a method like GetBusinessServiceByServiceId legitimate in this case?

EDIT:
This model is used as a strongly typed model for an ASP.NET MVC page, so it essentially acts like a ViewModel

  • 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-24T08:11:33+00:00Added an answer on May 24, 2026 at 8:11 am

    I’d say no. If a ViewModel requires a BusinessService object it should be given it by the Controller; finding a BusinessService object by its id is the job of a Repository class, which a ViewModel is not. Also, in the example given, BusinessServices should be injected into the Controller in its constructor and accessed via in an interface rather than statically; the code example you’ve got there would be pretty difficult to test.

    I personally use ViewModels as data holders containing model data and properties indicating if a View should display certain elements.

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

Sidebar

Related Questions

I have a bunch of rails models that I'm re-writing into a single model
I am writing a piece of code in my controller that is suposed to
I'm writing some code that will need to speak to a web service over
For the past few days I've been writing classes that at first I thought
I remember writing this code in the past, so I could do it again,
I want to start writing some blog and I know that i will past
In past, I am using Listview and using below code can show a particular
For the past few weeks, I've been trying to learn about just how email
I am writing a simple prototype code to demonstrate & profile I/O schemes (HDF4,
I am writing a PHP script that will launch a program on the server.

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.