日期:2014-05-16 浏览次数:20433 次
MovieDBContext db = new MovieDBContext();
public ActionResult Index()
{
var movies = db.Moviesa.ToList();
return View(movies);
}
public class Movie
{
//定義數據
public int ID { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
//建立MovieDBContext处理數據的存取与更新
public class MovieDBContext : DbContext
{
public DbSet<Movie> Moviesa { get; set; }
}
@model IEnumerable<MvcMovie.Models.Movie>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
Title
</th>
<th>
ReleaseDate
</th>
<th>
Genre
</th>
<th>
Price
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
&