类型“ IEnumerable<>”在未引用的程序集中定义

编程入门 行业动态 更新时间:2024-10-24 08:28:46
本文介绍了类型“ IEnumerable<>”在未引用的程序集中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已将以下nuget包添加到我的MVC 5应用程序X.PagedList.Mvc

I have added the following nuget package to my MVC 5 application X.PagedList.Mvc

我在控制器/视图中返回结果如下:

I return the results in my controller/view as follows:

// Repo public IPagedList<Post> GetPagedPosts(int pageNumber, int pageSize) { var posts = _context.Post .Include(x => x.Category) .Include(x => x.Type); // Return a paged list return posts.ToPagedList(pageNumber, pageSize); } // View model public class PostViewModel { public IPagedList<Post> Posts { get; set; } ... } // Controller method public ActionResult Index(int? page) { int pageNumber = page ?? 1; int pagesize = 5; var posts = _PostRepository.GetPagedPosts(pageNumber, pagesize); var viewModel = new PostViewModel { Posts = posts, ... }; return View(viewModel); } // View @model MyApp.ViewModels.PostViewModel @using X.PagedList.Mvc; @using X.PagedList; <p>Page @(Model.Posts.PageCount < Model.Posts.PageNumber ? 0 : Model.Posts.PageNumber) of @Model.Posts.PageCount </p>

但是在我看来,我收到以下错误 Type'IEnumerable< >'是在未引用的程序集中定义的。 System.Runtime ...

But in my view I am getting the following error The type 'IEnumerable<>' is defined in an assembly that is not referenced. System.Runtime...

我的应用程序中没有project.json文件,这是什么错误?

I have no project.json file in my application so what is this error?

推荐答案

确保Web.config文件中包含以下行:

Make sure you have the following lines in your Web.config file:

<compilation debug="true" targetFramework="4.6.1"> //don't need to change THIS line, just the content of this section <assemblies> <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <add assembly="System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </assemblies> </compilation>

更多推荐

类型“ IEnumerable&lt;&gt;”在未引用的程序集中定义

本文发布于:2023-11-03 20:12:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定义   类型   程序   IEnumerable   lt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!