What is the correct way to populate a model for UserControl?

The question is not MVC, but the code architecture.

I have a partial view that takes 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 level and receives data from the database using the Entity Framework

My question is: what is a “good” and correct way to fill in CompanyModel?:

Solution 1

Create CompanyBag

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

and Project.GetCompanyInfo()return CompanyBag, and in the text CompanyModelI will fill in the model.

Decision 2

Project.GetCompanyInfo()will return CompanyModel(and therefore no helper class is needed) and I will write Modelin .ctorCompanyModel

Decision 3

maybe your decision?

UPDATE: LoadController Load, Factory. , Html.RenderPartial(viewName, viewModel). , CompanyModel - , , .

, : GetCompanyInfo a CompanyBag CompanyModel, .ctor?

+3
2

, , :)

, LoadController ViewModel, ViewModel . :

-, ViewUserControl<TViewModel>, LoadController , ViewModel , , , .

-, IViewModelFactory<TViewModel> ViewModel, ; , ViewModel .

, LoadController ViewModel, , , IViewModelFactory .

, LoadController IViewModelFactory ViewModel, .

, : CompanyViewModel Company CompanyViewModelFactory, UserViewModel User UserViewModelFactory ..::)

+2

Enhanced Query Objects ViewModel Full Entity?

http://www.yellowfeather.co.uk/2011/03/enhanced-query-objects-with-sharp-architecture/

, NHibernate, , , .

, , . , # 2. .

0

All Articles