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?