我正在开一个笑话网络应用程序.
我使用C#,实体框架,MVC,我做代码优先.
现在,当我尝试在我的数据库中读出某些内容时,我在标题中显示的错误就会显示出来.我不知道该寻找什么.我抬头看谷歌,但我没有得到答案......
我尝试提供您可能需要知道的所有代码:
public class Context : DbContext
{
public DbSet<Categorie> Categories {get;set;}
public Context() : base("Witze_DB")
{
}
}
public class HomeController : Controller
{
private Context db;
public HomeController(Context db)
{
this.db = db;
}
public ActionResult Index()
{
var allCats = db.Categories;
return View(allCats);
}
}
Run Code Online (Sandbox Code Playgroud)
这是Index.cshtml文件:
@model IEnumerable<Witze.Categorie>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th></th>
</tr>
@foreach (var item in Model) …Run Code Online (Sandbox Code Playgroud)