错误"不包含'选择'的定义,也没有扩展方法'选择'



我在构建 asp.net mvc 解决方案时遇到一个错误,但我能够获取带有数据的数据表,但不知道为什么我会收到此错误。也许我需要在某处添加 LINQ 引用。

接近Model.Select.

法典:

@model List<smartpond.Models.FeederPillar>
<table id="listing" 
class="table table-bordered table-striped table-responsive table-hover">
<thead>
<tr>
<th>Sl no</th>
<th>Time</th>
<th>R Voltage</th>
<th>Y Voltage</th>
<th>B Voltage</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Select((value, i) => new { i, value }))
{
<tr class="tr_@item.value.deviceid">
<td>@(item.i + 1)</td>
<td>@item.value.datetime</td>
<td>@item.value.RVoltage</td>
<td>@item.value.YVoltage</td>
<td>@item.value.BVoltage</td>
</tr>
}
</tbody>
</table>

在 Razor 页面顶部添加以下 using 语句

@using System.Linq

试试这个

@foreach (var item in Model)
{
<tr>
<td>@item.id</td>
<td>@item.datetime</td>
<td>@item.RVoltage</td>
<td>@item.YVoltage</td>
<td>@item.BVoltage</td>
</tr>
}

最新更新