c# - Data travel from DAL to MVC View -


asp.net mvc4

i have business layer dll communicates dal , retrieves classes like:

public class productionparameter     {         public string companycode { get; set; }         public string unitcode { get; set; }         public string itemdescriptionlocal { get; set; }         public string itemdescriptionenglish { get; set; }         public string consumeditemdescriptionlocal { get; set; }         public string consumeditemdescriptionenglish { get; set; }         public string lotcategory1description { get; set; }         public string lotcategory2description { get; set; }         public string lotcategory3description { get; set; }         public string lotcategory1code { get; set; }         public string lotcategory2code { get; set; }         public string lotcategory3code { get; set; }         public string linecode { get; set; }         public string linecodedisplay { get; set; }          public list<pallet> palletsproduced { get; set; }      } 

my controller gets above info view doesnt need above.

for example lets 3 production parameters classes each 1 has 20 pallets. means each productionparameter has 20 pallets produced.

i want show mvc view consolidated data each production parameter.

how correctly?

standard case:

do create in models class info need view , define class in @model directive?

ajax:

what changes if want make via ajax? ajax call return consolidated data or full data , let angularjs or jquery make consolidation on client?

you can use viewmodels keeping business logic separate views.a viewmodel represents data want have displayed on view/page.

lets have productionparameterclass contains following properties:

public class productionparameter {    public string companycode { get; set; }    public string unitcode { get; set; }    public string itemdescriptionlocal { get; set; }    public string itemdescriptionenglish { get; set; }    public string consumeditemdescriptionlocal { get; set; }    public string consumeditemdescriptionenglish { get; set; }    public string lotcategory1description { get; set; }    public string lotcategory2description { get; set; }    public string lotcategory3description { get; set; }    public string lotcategory1code { get; set; }    public string lotcategory2code { get; set; }    public string lotcategory3code { get; set; }    public string linecode { get; set; }    public string linecodedisplay { get; set; }    public list<pallet> palletsproduced { get; set; } } 

view models differ domain models in view models contain data (represented properties) want use on view.

suppose, want display following properties on view, viewmodel can

 public class productionparameterviewmodel  {     public string companycode { get; set; }     public string unitcode { get; set; }     public string itemdescriptionlocal { get; set; }     public string itemdescriptionenglish { get; set; }     public string consumeditemdescriptionlocal { get; set; }     public string consumeditemdescriptionenglish { get; set; }     public string linecodedisplay { get; set; }     public list<pallet> palletsproduced { get; set; }   }  

then , on view, can use below:

@model myproject.viewmodels.productionparameterviewmodel 

edit:

if have 2 models, can put them in single model below:

public class viewmodel1 {  }  public class viewmodel2 {  }  public class myaggregatemodel {    public viewmodel1 model1 { get; set;}     public viewmodel2 model2 { get; set;} } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -