I am working on MVC3 asp.net.
this is my sr=tatement in controller:-
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 code in View:-
@foreach(var album in ViewBag.rawMaterialRequired)
{
@album<br />
}
</div>
this is my output:-
{ Description = Polymer 26500, Quantity = 10 }
{ Description = Polymer LD-M50, Quantity = 10 }
{ Description = Titanium R-104, Quantity = 20 }
this is my desired output:-

Start by designing a view model:
then in your controller use this view model:
and inside the view:
That’s was the first step into improving your code. The second step consists of getting rid of
ViewBagand use strongly typed views and display templates:and in the view remove any ugly loops thanks to display templates:
and inside the display template (
~/Views/Shared/DisplayTemplates/ProductLineViewModel.cshtml):