asp.net-mvc-3 - 在 MVC 3 Razor View 中找不到命名空间

标签 asp.net-mvc-3 razor

我正在将 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/

相关文章:

c# - asp.net mvc 3 WebCache 奇怪的行为

c# - 使用 Razor 和 MVC 处理 C# 中按钮的单击事件

javascript - 将 Javascript 中的值返回到 C# HTML 文件

c# - @onkeypress 没有获取文本输入框的更新值?

c# - cshtml图片链接可点击区域太大

c# - 无法对空引用执行运行时绑定(bind),但它不是空引用

asp.net - MVC3 OutputCache VaryByHeader=Cookie 未设置

asp.net-mvc - 带有单选按钮的 ASP.Net MVC3 ViewModel 不起作用

asp.net-mvc-3 - ASP.NET MVC 3 jquery.validate.unobtrusive.js 的许可证?

asp.net-mvc-3 - MVC 3 POST 数据和 Id 字段