我如何发送两个表中的数据列表以供查看?
How i can send list of data from two tables to view?
我在 asp mvc 应用程序数据库中工作,首先是一个 broach 所以我有两个表 Employee 和 Branch,我需要发送列表以查看 Employee name 和 branch name 这是我的控制器代码
public PartialViewResult List()
{
List<Employee> emp;
using (var contxt = new EnglisCenterEntities())
{
var query = contxt.Employee.ToList();
emp = query;
}
return PartialView(emp);
}
我的查看代码是
@model IEnumerable<Insert.Models.Employee>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.EmpName)
</th>
<th>
@Html.DisplayNameFor(model => model.Phone)
</th>
<th>
@Html.DisplayNameFor(model => model.Username)
</th>
<th>
@Html.DisplayNameFor(model => model.Branches.BranchName)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.EmpName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Phone)
</td>
<td>
@Html.DisplayFor(modelItem => item.Username)
</td>
<td>
@Html.DisplayFor(modelItem => item.Branches.BranchName)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.IdEmp }) |
@Html.ActionLink("Details", "Details", new { id=item.IdEmp }) |
@Html.ActionLink("Delete", "Delete", new { id=item.IdEmp })
</td>
</tr>
}
但它不起作用,所以我如何发送带有员工数据的分支机构名称
这里是:
public PartialViewResult List()
{
List<Employee> emp;
using (var contxt = new EnglisCenterEntities())
{
var brands = contxt.Employee.Include("Branches").ToList();
// var query = contxt.Employee.ToList();
emp = brands;
}
return PartialView(emp);
}
谢谢大家 :)
我在 asp mvc 应用程序数据库中工作,首先是一个 broach 所以我有两个表 Employee 和 Branch,我需要发送列表以查看 Employee name 和 branch name 这是我的控制器代码
public PartialViewResult List()
{
List<Employee> emp;
using (var contxt = new EnglisCenterEntities())
{
var query = contxt.Employee.ToList();
emp = query;
}
return PartialView(emp);
}
我的查看代码是
@model IEnumerable<Insert.Models.Employee>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.EmpName)
</th>
<th>
@Html.DisplayNameFor(model => model.Phone)
</th>
<th>
@Html.DisplayNameFor(model => model.Username)
</th>
<th>
@Html.DisplayNameFor(model => model.Branches.BranchName)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.EmpName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Phone)
</td>
<td>
@Html.DisplayFor(modelItem => item.Username)
</td>
<td>
@Html.DisplayFor(modelItem => item.Branches.BranchName)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.IdEmp }) |
@Html.ActionLink("Details", "Details", new { id=item.IdEmp }) |
@Html.ActionLink("Delete", "Delete", new { id=item.IdEmp })
</td>
</tr>
}
但它不起作用,所以我如何发送带有员工数据的分支机构名称
这里是:
public PartialViewResult List()
{
List<Employee> emp;
using (var contxt = new EnglisCenterEntities())
{
var brands = contxt.Employee.Include("Branches").ToList();
// var query = contxt.Employee.ToList();
emp = brands;
}
return PartialView(emp);
}
谢谢大家 :)