问题描述
当我使用我的模型值连接到数据库时,会出现此错误。任何人都可以帮助我 这里是我的代码: 公开覆盖列表< appdto>预约名单(int id) { List< appdto> dto = new List< appdto>(); List< appointment> db = _db.Appointments.Where(p => p.DID == id).ToList(); foreach(db中的var s) { var app = new AppDto(); app.PID = s.PID; app.Title = s.Title; app.Length = s.Length; app.AppDate = s.AppDate; dto.Add(app) ; } 返回dto; }
解决方案你可以尝试使用@model更改为@model IEnumerable< your model => 绑定当前模型的地方。
When i am connecting to the database with my model values then this error is getting. Can any one help me out here is my code: public override List<appdto> Appointmentlist(int id) { List<appdto> dto = new List<appdto>(); List<appointment> db = _db.Appointments.Where(p => p.DID==id).ToList(); foreach (var s in db) { var app = new AppDto(); app.PID = s.PID; app.Title = s.Title; app.Length = s.Length; app.AppDate = s.AppDate; dto.Add(app); } return dto; }
解决方案 can you try to change in view using @model to @model IEnumerable<your model=""> where you bind your current model.