ASP.NET MVC4: How to convert an IEnumerable to a string for ViewBag

Posted by sehummel on Stack Overflow See other posts from Stack Overflow or by sehummel
Published on 2012-12-12T17:00:57Z Indexed on 2012/12/12 17:03 UTC
Read the original article Hit count: 271

Filed under:
|

This is what I'm trying to do, but it doesn't work:

HardwareType hwt = new HardwareType { HType = "PC" };
IEnumerable<Hardware> Pcs = db.Hardware.Where(h => h.HardwareType.Contains(hwt));
ViewBag.Pcs = Pcs.ToString();

So how do I convert my IEnumerable to a string (or other primitive data type) so the compiler won't give me an error when I try to use it in my Razor?

@foreach (var item in ViewBag.Pcs) {
     <li><a href="#" class="btn"><i class="icon-hdd"></i> @item.HType</a></li>
}

© Stack Overflow or respective owner

Related posts about Razor

Related posts about asp.net-mvc-4