我是ASP.NET MVC的新手。我拥有的是:-数据库中的一个表,其中包含以下列中的生产数据: machine_name、good_parts、bad_parts、date。
基于MS教程的ASP.NEt MVC5,我构建了一个简单的应用程序来显示数据库中的数据。
我想要的是:我想通过machine_name过滤结果,因为DB中有太多的记录,浏览器在呈现结果时挂起。
控制器看起来是这样的:
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>
}
}在实现if语句之后,视图不会从DB返回任何记录。提前谢谢你花时间解释我的基本知识。
马辛。
发布于 2018-09-26 07:27:11
就像很容易
db.DATABASE.Where(x => x.MachineName == "something").ToList()或
db.DATABASE.Take(100).ToList()根据谓词筛选值序列。
Enumerable.Take(IEnumerable,Int32)方法
QueryableExtensions.Take Method (IQueryable, Expression>)
从序列开始返回指定数目的连续元素。
发布于 2018-09-26 07:36:12
你可以试试这个:
db.DATABASE.Where(item=>item.machine_name =="machine1").ToList();https://stackoverflow.com/questions/52512200
复制相似问题