本文介绍了使用linq从数据库中检索配置文件页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好,我正在尝试获取当前用户的个人资料页面,但我在屏幕上看到错误,我不知道它来自哪里。拜托,我需要任何对这个问题有明确答案的程序员的答案。详见以下内容: 错误: 传入字典的模型项目是类型System.Linq.Enumerable + WhereSelectListIterator`2 [Community.Models.Person.Profile,f__AnonymousType5`11 [System.String,System.String,System.String,System.String,System.String,System.String,System。 DateTime,System.String,System.Int32,System.Int32,System.Int32]],但此字典需要System.Collections.Generic.IEnumerable`1 [Community.Models.Person.Profile]类型的模型项。 /> 我在个人资料控制器中的代码: [授权] public ActionResult Proffe() { var profiles =(来自d中的db.Profiles.ToList() 其中d .Username == User.Identity.Name 选择新{ FirstName = d.FirstName, LastName = d.LastName, 地址= d.Address, Email = d.Email, Phone = d.Phone, Country = d.Country , DateOfBirth = d.DateOfBirth, 描述= d.Description, ProfileId = d.ProfileId, Comment = d.Comments.Count, Post = d.Posts.Count< i>< / i> })。AsEnumerable(); 返回查看(个人资料); } 解决方案 Hello, i am trying to get the profile page of the current user but i am seeing an error on my screen and i don't know where it seems to be coming from. please, i need answers from any programmer that has a definite answer to this question. see below for details:ERROR:The model item passed into the dictionary is of type System.Linq.Enumerable+WhereSelectListIterator`2[Community.Models.Person.Profile,f__AnonymousType5`11[System.String,System.String,System.String,System.String,System.String,System.String,System.DateTime,System.String,System.Int32,System.Int32,System.Int32]], but this dictionary requires a model item of type System.Collections.Generic.IEnumerable`1[Community.Models.Person.Profile].My code in profile controller: [Authorize] public ActionResult Proffe() { var profiles = (from d in db.Profiles.ToList() where d.Username == User.Identity.Name select new{ FirstName = d.FirstName, LastName = d.LastName, Address = d.Address, Email = d.Email, Phone = d.Phone, Country = d.Country, DateOfBirth = d.DateOfBirth, Description = d.Description, ProfileId = d.ProfileId, Comment = d.Comments.Count, Post = d.Posts.Count<i></i> }).AsEnumerable(); return View(profiles); } 解决方案 这篇关于使用linq从数据库中检索配置文件页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-06 01:53