传递到字典中的模型项的类型为'System.Collections.Generic.List`1 [AppModels.Models.AppDto]',但此字典需要类型为'AppModels.Models.AppDto的模型项 [英] The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[AppModels.Models.AppDto]', but this dictionary requires a model item of type 'AppModels.Models.AppDto

查看:329
本文介绍了传递到字典中的模型项的类型为'System.Collections.Generic.List`1 [AppModels.Models.AppDto]',但此字典需要类型为'AppModels.Models.AppDto的模型项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用我的模型值连接到数据库时,会出现此错误。任何人都可以帮助我



这里是我的代码:



公开覆盖列表< 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.


这篇关于传递到字典中的模型项的类型为'System.Collections.Generic.List`1 [AppModels.Models.AppDto]',但此字典需要类型为'AppModels.Models.AppDto的模型项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆