开发者

how can get value separately of a query

开发者 https://www.devze.com 2023-03-14 09:20 出处:网络
in MVC3 开发者_如何学运维asp.net this is my controller statement:- ViewBag.rawMaterialRequired = (from x in db.RawMaterial

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:-

how can get value separately of a query

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消