ASP.net MVC - create query in model -
i'm novice @ mvc . have 3 models: department, unit, employees.
public class department { public int departmentid { get; set; } public string departmentname { get; set; } public int managerid { get; set; } } public class unit { public int unitid { get; set; } public string unitname { get; set; } public int managerid } public class employees { public int employeeid { get; set; } public string employeename { get; set; } }
i want edit objects unit , department in single view. use structure view model:
public class structuremodel { public ienumerable<departments> departments { get; set; } public ienumerable<units> units { get; set; } public ienumerable<employee> employees { get; set; } }
i want have in view tables departments , units column managername instead managerid (managername == employeename unit.managerid == employee.employeeid) . controller:
private registraicontext db = new registraicontext(); public actionresult index() { var model = new structuremodel(); model.departments = db.departmentss.tolist().orderby(r => r.departmid); model.units = db.unitss.tolist().orderby(r => r.unitid); return view(model); }
and view (i use grid.mvc)
@model registrai.models.structuremodel @using gridmvc.html @html.grid(model.unit).columns(columns => { columns.add(model => model.unitid).titled("uniid") columns.add(model => model.unitname).titled("unitname"); columns.add(model => model.managername).titled("manager"); } .........................
where (in model unit, in structuremodel or in controller) , how create query retrieve managername db , how modify models unit , department add property managername ? thank
Comments
Post a Comment