Reputation: 1
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? 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.
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.
//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 (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.
Upvotes: 0
Views: 468
Reputation: 1
As originally thought, the where clause is what I needed. It was just a matter of where and what so what I did was: Add the where clause in the if statement. Fairly simple, was a bit of a brain teaser for me.
model.RequestDetailsList = newRequestList.Where(x => x.RequestId == model.SelectedItemsId).ToList();
Upvotes: 0
Reputation: 79
I am slightly confused by this question but would like to help. Find will return a single Item so SelectedItems is a little confusing.
What you want is something along the lines of:
newRequestList.Where(model => model.RequestId == id && model.SelectedItemsId == id);
Upvotes: 2