[英]Return field with matching id's (specific id)
I have a master-detail page that when you click view details on a request, it populates data on a table below. 我有一个主从页面,当您单击请求上的查看详细信息时,它将在下表中填充数据。 When user clicks view details on the request, how can I have the second table populate the data that has matching ids?
当用户单击请求上的查看详细信息时,如何让第二个表填充具有匹配ID的数据? When I iterate through now, it finds the ids that do match but they are going to all match if I can't capture the selected item id and go through to find the rows that have that same id.
当我现在进行遍历时,它会找到确实匹配的ID,但是如果我无法捕获所选的项目ID并去查找具有相同ID的行,它们将全部匹配。
Top table is the requests and the bottom table is the request details. 上表是请求,下表是请求详细信息。
This is the code in my requests controller that grabs the data from request details. 这是我的请求控制器中的代码,可从请求详细信息中获取数据。 I am finding the id and trying to compare that with the selected item but im still getting all records back.
我正在查找ID,并尝试将其与所选项目进行比较,但即时通讯仍会取回所有记录。
//Requests Controller
public ActionResult Index(IA_RequestDetails iA_RequestDetails, IA_Requests iA_Requests, long? id = null)
{
List<IA_Requests> requestList = db.IA_Requests.ToList();
List<IA_RequestDetails> newRequestList = db.IA_RequestDetails.ToList();
var model = new InventoryAnalysisMasterDetailsModel();
model.RequestDetailsList = newRequestList;
model.RequestList = requestList;
if (id != null)
{
model.SelectedItems = newRequestList.Find(model => model.RequestId == id && model.SelectedItemsId == id);
model.SelectedItemsId = id;
}
return View(model);
}
In my view I am using a foreach statement 我认为我正在使用foreach语句
foreach (var item in Model.RequestDetailsList)
{
<tr>
<td>
@item.RequestId
</td>
<td>
@item.Item
</td>
<td>
@item.LineID
</td>
<td>
@Html.ActionLink("Edit Item", "Edit", new { id = item.LineID, controller = "IA_RequestDetails" }) |
@Html.ActionLink("View Item Details", "Details", new { id = item.LineID, controller = "IA_RequestDetails" })
</td>
</tr>
}
Any help is very much appreciated. 很感谢任何形式的帮助。 Thank you.
谢谢。
I am slightly confused by this question but would like to help. 这个问题让我有些困惑,但是想提供帮助。 Find will return a single Item so SelectedItems is a little confusing.
Find将返回单个Item,因此SelectedItems有点令人困惑。
What you want is something along the lines of: 您想要的是以下内容:
newRequestList.Where(model => model.RequestId == id && model.SelectedItemsId == id);
As originally thought, the where clause is what I needed. 如最初的想法,where子句是我所需要的。 It was just a matter of where and what so what I did was: Add the where clause in the if statement.
这只是我在哪里以及做什么的问题:在if语句中添加where子句。 Fairly simple, was a bit of a brain teaser for me.
相当简单,对我来说有点麻烦。
model.RequestDetailsList = newRequestList.Where(x => x.RequestId == model.SelectedItemsId).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.