Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc ASP.net MVC-在模型中创建查询_Asp.net Mvc - Fatal编程技术网

Asp.net mvc ASP.net 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

我是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; 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");
}
.........................