Asp.net mvc ASP.net MVC-在模型中创建查询
我是MVC的新手。我有三种模式:部门、单位、员工Asp.net mvc ASP.net MVC-在模型中创建查询,asp.net-mvc,Asp.net Mvc,我是MVC的新手。我有三种模式:部门、单位、员工 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
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; }
}
我想在单一视图中编辑对象单位和部门。我使用结构视图模型:
public class StructureModel
{
public IEnumerable<Departments> Departments { get; set; }
public IEnumerable<Units> Units { get; set; }
public IEnumerable<Employee> Employees { get; set; }
}
最后是我的视图(我使用Grid.Mvc)
在何处(在模型单元、结构模型或控制器中),以及如何创建查询以从数据库检索ManagerName,以及如何修改模型单元和部门以添加属性ManagerName?
谢谢您需要特定于视图要求的视图模型扫描代码帮助?
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);
}
@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");
}
.........................