C# Filtering.ToList()
我是ASP.NETMVC新手。我所拥有的: -具有一个表的数据库,该表包含以下列中的生产数据: 机器名称、好零件、坏零件、日期 基于ASP.NETMVC5的MS教程,我构建了一个简单的应用程序来显示数据库中的数据 我想要的是: 我想按机器名称过滤结果,因为数据库中的记录太多,渲染结果时浏览器挂起 控制器看起来像:C# Filtering.ToList(),c#,asp.net,asp.net-mvc-5,C#,Asp.net,Asp.net Mvc 5,我是ASP.NETMVC新手。我所拥有的: -具有一个表的数据库,该表包含以下列中的生产数据: 机器名称、好零件、坏零件、日期 基于ASP.NETMVC5的MS教程,我构建了一个简单的应用程序来显示数据库中的数据 我想要的是: 我想按机器名称过滤结果,因为数据库中的记录太多,渲染结果时浏览器挂起 控制器看起来像: public ActionResult Index() { return View(db.DATABASE.ToList());
public ActionResult Index()
{
return View(db.DATABASE.ToList());
}
查看页面:
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.machine_name)
</th>
<th>
@Html.DisplayNameFor(model => model.date)
</th>
<th>
@Html.DisplayNameFor(model => model.good_parts)
</th>
<th>
@Html.DisplayNameFor(model => model.bad_parts)
</th>
</tr>
@foreach (var item in Model)
{
if (item.machine_name == "machine_1")
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.machine_name)
</td>
<td>
@Html.DisplayFor(modelItem => item.data)
</td>
<td>
@Html.DisplayFor(modelItem => item.good_parts)
</td>
<td>
@Html.DisplayFor(modelItem => item.bad_parts)
</td>
</tr>
}
}
@Html.DisplayNameFor(model=>model.machine\u name)
@DisplayNameFor(model=>model.date)
@DisplayNameFor(model=>model.good\u部分)
@DisplayNameFor(model=>model.bad\u部分)
@foreach(模型中的var项目)
{
如果(item.machine\u name==“machine\u 1”)
{
@DisplayFor(modelItem=>item.machine\u name)
@DisplayFor(modelItem=>item.data)
@DisplayFor(modelItem=>item.good\u部件)
@DisplayFor(modelItem=>item.bad\u部件)
}
}
在实现if语句之后,view不会从DB返回任何记录。
非常感谢你花时间给我解释基本知识
Marcin.这很容易
db.DATABASE.Where(x => x.MachineName == "something").ToList()
或
基于谓词筛选值序列 从一个数组的开头返回指定数量的连续元素 序列 这很容易
db.DATABASE.Where(x => x.MachineName == "something").ToList()
或
基于谓词筛选值序列 从一个数组的开头返回指定数量的连续元素 序列 您可以尝试以下方法:
db.DATABASE.Where(item=>item.machine_name =="machine1").ToList();
您可以尝试以下方法:
db.DATABASE.Where(item=>item.machine_name =="machine1").ToList();