我已经为SQL Server视图创建了Linq-to-SQL,现在我正在尝试在视图上显示记录,已经完成了:)但是
控制器:
namespace EmployeeAttendance_app.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Employee Attendance";
var DataContext = new EmployeeAtdDataContext();
var EmployeeAtd = from emp in DataContext.EmployeeAtds
select emp;
return View(EmployeeAtd);
}
}
查看:
<ul>
@foreach (EmployeeAttendance_app.Models.EmployeeAtd emp in (IEnumerable<Object>)ViewData.Model)
{
<li>@emp.EmplName</li>
}
</ul>
模型包含名为EmployeesAtd
的Linq-to-SQL类。
已通过此查询创建了视图:
SELECT
dbo.HrEmployee.EmplID, dbo.HrEmployee.EmplName, dbo.AtdRecord.RecDate,
dbo.AtdRecord.RecTime, dbo.HrDept.DeptName
FROM
dbo.HrDept
RIGHT OUTER JOIN
dbo.HrEmployee ON dbo.HrDept.DeptID = dbo.HrEmployee.DeptID
LEFT OUTER JOIN
dbo.AtdRecord ON dbo.HrEmployee.EmplID = dbo.AtdRecord.EmplID
答案 0 :(得分:0)
除了清理阿德里亚诺指出的事情外,我没有看到任何错误。你说EmployeeAtds是一个SQL View,对吧?我猜你有某种重复行的连接。
答案 1 :(得分:0)
尝试在循环前移动拳击:
var emps = (IEnumerable< Object >)ViewData.Model;
@foreach(EmployeeAttendance_app.Models.EmployeeAtd emp in emps)
要在GridView中显示数据,您必须使用一些javascript库。 grid controls for ASP.NET MVC?