我通过将数据库资源管理器中的表拖放到O / R设计器中来创建DataContext
。
当我在控制器中尝试以下代码时,我的视图中没有显示任何内容
Table<week> weektab = context.GetTable<week>();
var report = from w in weektab select new myModel(){col1, col2...};
return PartialView(report);
我的部分视图是强类型的,我在foreach
循环中显示模型的字段。该代码适用于其他表,但不显示Week
表的任何内容。我错过了什么?
编辑1:我确认Week
表有110行。
编辑2:
这是代码
Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace proj.Models
{
public class WeeklyReportModel
{
public string name { get; set; }
public string mon { get; set; }
public string tue { get; set; }
public string wed { get; set; }
public string thu { get; set; }
public string fri { get; set; }
public string sat { get; set; }
}
}
Controller snippet
public PartialViewResult showResult(string unit, string day)
{
this.context = new projDataContext(ConfigurationManager.ConnectionStrings["constr"].ToString());
...
Table<week> weektab = context.GetTable<week>();
...
var report = from sat1 in weektab
select new WeeklyReportModel{ name = sat1.col1};
return PartialView(report);
}<br/>
PartialView
@using proj.Models
@model IEnumerable<WeeklyReportModel>
<table>
...
@foreach (var p in Model)
{
<tr>
<td>@p.name</td>
<td>@p.mon</td>
<td>@p.tue</td>
<td>@p.wed</td>
<td>@p.thu</td>
<td>@p.fri</td>
<td>@p.sat</td>
</tr>
}
</table>