Iterating between two queries within a single view.
In my application there is a comparison list of a specific product. At the top of the page, there is details of this product as its name, min/max price, photo and some other details.
What I need is something like this:
@modelComparisonList List<MyApp.Models.Products>
@modelProduct MyApp.Models.Products
@{
ViewBag.Title = "Comparing " + modelProduct.name;
}
<h1>There is @modelProduct.quantity products to compare</h1>
<table>
@foreach (var item in modelComparisonList)
{
<tr>
<p>@item.productName</p>
</tr>
<tr>
<p>@item.productPrice</p>
</tr>
<tr>
<p>@item.marketName</p>
</tr>
}
</table>
Can you understand my case?
I don't know how to perform a solution to resolve this. Can someone give me an idea?
Just make a wrapper class that contains both, ie simply:
public class TheViewModel
{
public List<MyApp.Models.Products> Item1 { get; set; }
public MyApp.Models.Products Item2 { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With