I am simply trying to retrieve some data from a database, and display it on the _Layouts.cshtml file. And i wanna do this in the with a method in the models folder, right??
My following script down here works, but it's not pretty, take a look.
Here is my model:
namespace MvcBreakingNews.Models
{
public class ListCategories
{
public IList<string> arrTest() {
IList<string> myList = new List<string>();
DataClassesDataContext dt = new DataClassesDataContext();
var q = from c in dt.categories select c;
foreach (var item in q)
{
myList.Add(item.category1.ToString());
}
return myList;
}
}
}
}
And here is my _Layout.cshtml
@using MvcBreakingNews.Models
...
@{
ListCategories objC = new ListCategories();
foreach (var item in objC.arrTest())
{
<li><a href="#">@item</a></li>
}
}
Now what i want to do, or what i think i want to do. Is to get rid of the foreach loop in my method and send the array directly to the _Layout.cshtml
How would i do this?