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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:35:24+00:00 2026-05-22T23:35:24+00:00

The question is not about MVC but more about code architecture. I have a

  • 0

The question is not about MVC but more about code architecture.

I have a partial view that takes a CompanyModel

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CompanyModel>" %>

<%: Html.TextAreaFor(m => m.Name) %>
<%: Html.TextAreaFor(m => m.Location) %>

CompanyModel

public class CompanyModel
{
     [LocalizedDisplayName("Name", NameResourceType = typeof(Resources.Views.CompanyBackground))]
     public string Name{get;set;}
     [LocalizedDisplayName("Location", NameResourceType = typeof(Resources.Views.CompanyBackground))]
     public string Location{get;set;}

     public CompanyModel()
     {
          var info = Project.GetCompanyInfo();
     }
}

Project.GetCompanyInfo() is the DAL layer and gets data from the DB using Entity Framework

My question: what is the “nice” and correct way to fill CompanyModel?:

Solution 1

Create CompanyBag

public class CompanyBag
{
     public string Name{get;set;}
     public string Location{get;set;}
}

and Project.GetCompanyInfo() will return the CompanyBag and in the .ctor of CompanyModel I’ll fill the Model.

Solution 2

Project.GetCompanyInfo() will return CompanyModel (and thus no helper class is needed) and I’ll fill the Model in the .ctor of CompanyModel

Solution 3

maybe your solution?

UPDATE:
I have LoadController with Load action and this action is kind of a Factory. It will take list of views and will create them by reflection and then load to the page by Html.RenderPartial(viewName, viewModel). So, CompanyModel is just one example of the views and therefore I need each view to be independent.

So my question is: should GetCompanyInfo return a CompanyBag or a CompanyModel and I’ll fill the Model in the .ctor?

Thank you

  • 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-22T23:35:25+00:00Added an answer on May 22, 2026 at 11:35 pm

    Ok, following the question update, here’s my updated answer 🙂

    I’m assuming the different Views LoadController populates take different types of ViewModel, and each ViewModel is populated from a different part of the domain model. Here’s how I’d tackle that:

    Firstly, create each partial View as a strongly-typed subclass of ViewUserControl<TViewModel>, so LoadController can figure out which ViewModel type it needs for each of the Views it is told to create.

    Secondly, define an IViewModelFactory<TViewModel> interface, and create one implementation for each ViewModel type you require; each implementation will know how to create and populate its ViewModel type from your domain model.

    Finally, LoadController would figure out the type of ViewModel it needs for each view it’s been asked to create, and use the appropriate IViewModelFactory to create it.

    To avoid unnecessary overhead, LoadController could find all the available IViewModelFactory implementations at runtime, and keep a static store of them against the type of ViewModel they create.

    So to sum up: I would populate CompanyViewModel from a Company using a CompanyViewModelFactory, I would populate a UserViewModel from a User using a UserViewModelFactory, etc. 🙂

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

Sidebar

Related Questions

My question is not about a specific code snippet but more general, so please
I have a question about MVC. Particularly about models. Suppose that I have a
(note that this question is not about CAS, it's about the May fail spuriously
This is not a question about jQuery, but about how jQuery implements such a
First off I'm not sure that's the proper title for this question but hopefully
This question is NOT about race-conditions, atomicity, or why you should use locks in
This question is not about which is the best, it is about which makes
This question is not about 'best' barcode library recommendation, we use various products on
This is a question not really about programming (is not specific to any language
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using

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.