I have a class called movie.cs in the modal which is as follows.
namespace CodFirst.Models
{
public class Movie
{
public int MovieId { get; set; }
public string name { get; set; }
public string genre { get; set; }
}
public class Student
{
public int StudentId { get; set; }
public string fname { get; set; }
public string lname { get; set; }
}
}
And i have a context class in the same modal called moviecontext as:
namespace CodFirst.Models
{
public class MovieContext:DbContext
{
public DbSet<Movie> Movies { get; set; }
public DbSet<Student> Students { get; set; }
}
}
Now i want to access the data of both Movies and student in the same view.But i am not able to access data of any one either.
IN the controller i have
MovieContext db = new MovieContext();
public ActionResult Index()
{
//db.Movies.ToList();
var myvar = db.Movies;
return View(myvar);
}
And finally the view is as follows:
@model CodFirst.Models.MovieContext
@{
ViewBag.Title = "Index";
}
@foreach(var item in Model.Movies)
{
@Html.DisplayName("movie: ") @item.name; @Html.DisplayName(" type: ") @item.genre; <br />
}