我在View
上收到错误消息传递到字典中的模型项的类型为' System.Collections.Generic.List' 1 [oneToOneRelationship.Student]',但此字典需要类型为&#39的模型项; System.Collections.Generic.IEnumerable' 1 [oneToOneRelationship.StudentDBContext]'
在运行应用程序时,数据库正在更新。
namespace oneToOneRelationship.Controllers
{
public class StudentController : Controller
{
StudentDBContext objContext;
public StudentController()
{
objContext = new StudentDBContext();
}
public ActionResult Index()
{
Student s = new Student
{
StudentId = 1,
StudentName = "Hitesh",
StudentAge = 24
};
StudentAccount sa = new StudentAccount {
StudentName = "Sports account",
StudentAmount = 300,
student = s
};
objContext.Students.Add(s);
objContext.StudentAccounts.Add(sa);
objContext.SaveChanges();
var result = from r in objContext.Students select r;
var data = objContext.Students.ToList();
return View(data);
}
}
}