I am trying to view list of items from database ( I am using Entity Framework).
My Repository method:
public List<string> getListOfItems(int i)
{
return (from x in db.Items where x.ID == i select x.Text).ToList();
}
My Controller:
public ActionResult Index()
{
var itemOutput = repo.getListOfItems(1); // I just put 1 since I didn't know how to specify "i" - However theoretically it should return first item in database but its not
ViewBag.itemOutput = itemOutput ;
return View();
}
Model:
public class items
{
[Key]
public int ID{ get; set; }
public string name{ get; set; }
public string quantity{ get; set; }
}
ItemModel:
public class itemModels
{
public List<List<string>> itemData{ get; set; }
}
View:
@foreach (var item in ViewBag.itemOutput )
{
<table id="t01">
<tr>
<td>@item.name</td>
</tr>
</table>
}
ViewBagunless you absolutely have to. If you don't know how to pass a model to your view, then you should go back to basics and follow some tutorials first.