我有 LINQ 查询从实体框架连接获取一些数据。我将数据从控制器传递到视图。运行代码时,我收到错误“指定的演员表无效。”
这是我的 LINQ 语句
var MeltAreaInformation =
new
{
Striko1 = (from item in db.tbl_dppITHr where item.ProductionHour >= SelectedDateDayShiftStart && item.ProductionHour <= SelectedDateDayShiftHr25End select item).Sum(x => x.Striko1) ?? 0,
Striko2 =
(from item in db.tbl_dppITHr
where item.ProductionHour >= SelectedDateDayShiftStart && item.ProductionHour <= SelectedDateDayShiftHr25End
select item).Sum(x => x.Striko2) ?? 0,
Striko3 =
(from item in db.tbl_dppITHr
where item.ProductionHour >= SelectedDateDayShiftStart && item.ProductionHour <= SelectedDateDayShiftHr25End
select item).Sum(x => x.Striko3) ?? 0,
Striko4 =
(from item in db.tbl_dppITHr
where item.ProductionHour >= SelectedDateDayShiftStart && item.ProductionHour <= SelectedDateDayShiftHr25End
select item).Sum(x => x.Striko4) ?? 0,
Striko5 =
(from item in db.tbl_dppITHr
where item.ProductionHour >= SelectedDateDayShiftStart && item.ProductionHour <= SelectedDateDayShiftHr25End
select item).Sum(x => x.Striko5) ?? 0,
Induction1 =
(from item in db.tbl_dppITHr
where item.ProductionHour >= SelectedDateDayShiftStart && item.ProductionHour <= SelectedDateDayShiftHr25End
select item).Sum(x => x.Inductotherm1) ?? 0,
Induction2 =
(from item in db.tbl_dppITHr
where item.ProductionHour >= SelectedDateDayShiftStart && item.ProductionHour <= SelectedDateDayShiftHr25End
select item).Sum(x => x.Inductotherm2) ?? 0,
};
ViewData["Striko2"] = MeltAreaInformation.Striko1.ToString();
现在,当我在 Var MeltAreaInformation 的调试和悬停中运行应用程序时,您可以看到它分配了以下内容。
以下是我用来在 HTML 页面上显示 ViewData 的 Razor 语法。
<table class="MeltTable">
<tr><th colspan="7">Total Weight Poured (kg's)</th></tr>
<tr><th>Striko 2</th><td class="MeltTableZero td @((int)ViewData["Striko2"] == 0 ? "red" : null)">@ViewData["Striko2"].ToString()</td></tr>
<tr><th>Striko 3</th><td class="MeltTableZero td @((int)ViewData["Striko3"] == 0 ? "red" : null)">@ViewData["Striko3"].ToString()</td></tr>
<tr><th>Striko 4</th><td class="MeltTableZero td @((int)ViewData["Striko4"] == 0 ? "red" : null)">@ViewData["Striko4"].ToString()</td></tr>
<tr><th>Striko 1</th><td class="MeltTableZero td @((int)ViewData["Striko1"] == 0 ? "red" : null)">@ViewData["Striko1"].ToString()</td></tr>
<tr><th>Striko 5</th><td class="MeltTableZero td @((int)ViewData["Striko5"] == 0 ? "red" : null)">@ViewData["Striko5"].ToString()</td></tr>
<tr><th>Induction 1</th><td class="MeltTableZero td @((int)ViewData["Inductotherm1"] == 0 ? "red" : null)">@ViewData["Inductotherm1"].ToString()</td></tr>
<tr><th>Induction 2</th><td class="MeltTableZero td @((int)ViewData["Inductotherm2"] == 0 ? "red" : null)">@ViewData["Inductotherm2"].ToString()</td></tr>
</table>
任何人都可以阐明这个问题。我试图手动分配值,但我仍然遇到同样的问题。