当我运行调试器时,我得到0个错误,布局加载,“电影”显示但实际上没有别的。我对MVC很新,一些输入将不胜感激。 View,Model和Controller的代码如下。该数据库包含100多个项目和一个列表,一个链接旨在出现,但它只是空白区域。
查看:
@model IEnumerable<MyWebPage.Models.Movie>
<h1>Movies</h1>
<ul>
@foreach (var item in Model.OrderBy(x => x.Name))
{
<li>@Html.ActionLink(item.Name, "Movies", new { id = item.ID })</li>
}
</ul>
控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyWebPage.Models;
namespace MyWebPage.Controllers
{
public class HomeController : Controller
{
private MoviesDbContext db = new MoviesDbContext();
public ActionResult Index()
{
return View(db.Movies.ToList());
}
public ViewResult Movies(int id)
{
Movie moviesdb = db.Movie.Find(id);
return View(moviesdb);
}
}
}
型号:
using System;
using System.Data.Entity;
namespace MyWebPage.Models
{
public class Movie
{
public int ID { get; set; }
public string Name { get; set; }
public string Cover { get; set; }
}
public class MoviesDbContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
}
}
提前致谢!