我正在将 PagedList 添加到我的 View 中,并大致遵循此 Tutorial 。我已经使用 Nuget 安装了 PagedList 引用,如下设置我的 Controller
public ViewResult Index(int page = 1)
{
List<Part> model = this.db.Parts.ToList();
const int pageSize = 20;
return View(model.ToPagedList(page, pageSize));
}
并在顶部使用以下模型写下了我的观点
@model PagedList.IPagedList<RIS.Models.Part>
当我运行页面时,出现以下错误
Compiler Error Message: CS0246: The type or namespace name 'PagedList' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 27:
Line 28:
Line 29: public class _Page_Areas_Parts_Views_Part_Index_cshtml : System.Web.Mvc.WebViewPage<PagedList.IPagedList<RIS.Models.Part>> {
PagedList dll 已正确加载到我的 Controller 中,因为当我将其从 View 中取出时,一切都会按预期工作。 CopyLocal 属性设置为“True”,我尝试将命名空间包含在我的特定区域的 Views\Web.Config 中。我还能做什么来让 View 看到命名空间?
最佳答案
我需要将命名空间添加到 View web.config 文件中。
详细信息在此SO post :
然后我需要关闭/重新打开 Visual Studio 2010 才能使其识别。编译项目没有帮助(web.config 可能只在项目加载时读取一次)。
关于asp.net-mvc-3 - 在 MVC 3 Razor View 中找不到命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8313308/