I am new to Entity framework.
I am working with Entity framework Code First, and created 4 classes.
The Schema is:
- Many users <-> Many Roles
- one User <-> Many Post
- Many Post <-> Many Tag
I have an area of Admin, and a controller called UsersController, with an ActionResult of returning a view.
public ActionResult Index()
{
return View();
}
I created a strongly typed view from ViewModels. In my viewmodels, I created a class with:
public class UsersIndex
{
public IEnumerable<User> Users { get; set; }
}
For my view, I've seen some code examples where the view can have a foreach loop:
@MyBlog.Areas.Admin.ViewModel
<tbody>
@foreach (var user in Model.Users)
{
<tr>
<td>@user.Id</td>
<td>@user.Username</td>
<td>@user.Email</td>
</tr>
}
</tbody>
But in my controller, how can I grab the users from my database to pass to my viewmodels into my view?