asp.net mvc3 数据读取的问题 20
model文件namespaceyijiaoMvc.Models.Entities{publicclassAdmin{publicintid{get;set;}publi...
model 文件
namespace yijiaoMvc.Models.Entities
{
public class Admin
{
public int id { get; set; }
public string admin_name{get;set; }
public string admin_key {get;set; }
}
}
using System.Data.Entity;
using yijiaoMvc.Models.Entities;
namespace yijiaoMvc.Models
{
public class yijiaoEntities : DbContext
{
public DbSet<Admin> Admin { get; set; }
}
}
control 文件里的
using yijiaoMvc.Models;
using yijiaoMvc.Models.Entities;
namespace yijiaoMvc.Controllers.Admin
{
public class AdminController : Controller
{
private yijiaoEntities db = new yijiaoEntities();
public ActionResult Index()
{
ViewBag.list = db.Admin.ToList();
return View(ViewBag.list);
}
}
}
view文件里的cshtml
@model yijiaoMvc.Models.Entities.Admin
@foreach (var db in ViewBag.list)
{
<p>@db.admin_key</p>
}
目前报错
传入字典的模型项的类型为“System.Collections.Generic.List`1[yijiaoMvc.Models.Entities.Admin]”,但此字典需要类型“yijiaoMvc.Models.Entities.Admin”的模型项
请问我错在哪里 还有
public DbSet<Admin> Admin { get; set; } 这个是什么意思?? 展开
namespace yijiaoMvc.Models.Entities
{
public class Admin
{
public int id { get; set; }
public string admin_name{get;set; }
public string admin_key {get;set; }
}
}
using System.Data.Entity;
using yijiaoMvc.Models.Entities;
namespace yijiaoMvc.Models
{
public class yijiaoEntities : DbContext
{
public DbSet<Admin> Admin { get; set; }
}
}
control 文件里的
using yijiaoMvc.Models;
using yijiaoMvc.Models.Entities;
namespace yijiaoMvc.Controllers.Admin
{
public class AdminController : Controller
{
private yijiaoEntities db = new yijiaoEntities();
public ActionResult Index()
{
ViewBag.list = db.Admin.ToList();
return View(ViewBag.list);
}
}
}
view文件里的cshtml
@model yijiaoMvc.Models.Entities.Admin
@foreach (var db in ViewBag.list)
{
<p>@db.admin_key</p>
}
目前报错
传入字典的模型项的类型为“System.Collections.Generic.List`1[yijiaoMvc.Models.Entities.Admin]”,但此字典需要类型“yijiaoMvc.Models.Entities.Admin”的模型项
请问我错在哪里 还有
public DbSet<Admin> Admin { get; set; } 这个是什么意思?? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询