c# - Multiple models in one view ASP.Net -


i new asp.net mvc. have 3 models employee, address, store. structures follows...

employee:-     empid(pk), empname, rank, storeid, addid store:-     storeid(pk), branchname, addid address:-     addid(pk), address, phone, id(fk employee.empid, fk store.storeid) 

how use 3 models in 1 controller , how perform crud operations in controller. in view of employee, want show fields of 3 of models, e.g.

empid, empname, rank, store.branchname, address, phone 

when update these fields in view, models should updated. know if how use multiple models without relationship between them. thanks.

this view model comes in handy. allows separate database layer fields , logic presentation layer fields.

you can combine several database entities , expose elements of each want display on front end.

for example, might define view model like:

public class employeeinfo {     public string employeename {get;set;}     // other properties      public employeeinfo(employee emp, store store, address address)     {         employeename = emp.empname;         // assign other properties     } } 

then, in controller, can create view model , pass view:

public class employeecontroller {      public iactionresult index()      {          var empinfo = new employeeinfo(employee, store, address); // retrieved database somehow          return view(empinfo);      } } 

then, view can reference view model , use properties normally.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -