gpt4 book ai didi

c# - 类型 'IEnumerable<>' 在未引用的程序集中定义

转载 作者:可可西里 更新时间:2023-11-01 03:00:10 24 4
gpt4 key购买 nike

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

我在我的 Controller / View 中返回结果如下:

// 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>

但在我看来,我收到了以下错误 The type 'IEnumerable<>' is defined in an assembly that is not referenced. System.Runtime...

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

最佳答案

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

<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>

关于c# - 类型 'IEnumerable<>' 在未引用的程序集中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38273842/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com