in MVC3 开发者_如何学运维asp.net this is my controller statement:-
ViewBag.rawMaterialRequired = (from x in db.RawMaterial
join y in db.ProductFormulation on x.ID equals y.RawMaterialID
where y.ProductID == p select new { x.Description, y.Quantity });
this is my View Code related to it:-
@foreach(var album in ViewBag.rawMaterialRequired)
{
@album<br />
}
So output is:-
{ Description = Polymer 26500, Quantity = 10 }
{ Description = Polymer LD-M50, Quantity = 10 }
{ Description = Titanium R-104, Quantity = 20 }
but i need this type of answer:-
please suggest me what should i do for it? Thank you in advance...
Create a RawMaterial class
public class RawMaterial
{
public string Description { get; set; }
public int Quantity { get; set; }
}
and use it instead of anonymous object
ViewBag.rawMaterialRequired = (from x in db.RawMaterial
join y in db.ProductFormulation on x.ID equals y.RawMaterialID
where y.ProductID == p select new RawMaterial { x.Description, y.Quantity });
and the view
<table>
<tr>
<th>Description</th>
<th>Quantity</th>
</tr>
@foreach(var album in ViewBag.rawMaterialRequired)
{
<tr>
<td>@album.Description</td>
<td>@album.Quantity</td>
</tr>
}
</table>
精彩评论