Namespace not found in MVC 3 Razor view

后端 未结 9 1162
情话喂你
情话喂你 2021-01-04 20:29

I am adding a PagedList to my view and loosely following this Tutorial. I have installed the PagedList reference using Nuget, set up my controller as follows



        
相关标签:
9条回答
  • 2021-01-04 21:07

    In my case, according to the package manager console, my project had a previous reference to PagedList however it was not showing up in my project references in the Solution Explorer.

    Solution for me was to use the package manager console to remove PagedList.MVC, then remove PagedList and then re-install them again like so:

    • uninstall-package PagedList.mvc
    • uninstall-package PagedList
    • install-package PagedList
    • install-package PagedList.mvc

    After that everything was good.

    0 讨论(0)
  • 2021-01-04 21:10

    In my case, I have to configure it in .cshtml, .cs and in web.config

    .cshtml

    @model PagedList.IPageList<namespace.model>
    @using PagedList.Mvc;
    

    Web.Config

    <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup> 
    

    .cs

    using PagedList;
    

    Hope this helps

    0 讨论(0)
  • 2021-01-04 21:11

    In my case, the error was complaining about PagedList.MVC and I had to also install:

    • PagedList.MVC

    not only PagedList.

    0 讨论(0)
  • 2021-01-04 21:12

    FYI for anyone else with the same problem as me here, it was stopping on the controller "using PagedList;" for me (which was correct), however the problem I had was in the view's web.config I had added the namespace reference "PageList" - which was spelled incorrectly! (Should have been PagedList - note the 'd').

    0 讨论(0)
  • 2021-01-04 21:12

    I have always had to import MvcPaging to my views in order to use PagedList. But I was using the library prior to Nuget so I don't know how the namespaces may have changed. In a VB.NET web forms view, I used <%@ Import Namespace="MvcPaging" %>

    0 讨论(0)
  • 2021-01-04 21:13

    I had this problem as well when using an assembly that wasn't set to "Copy Local", after changing the assembly reference properties it works as expected.

    0 讨论(0)
提交回复
热议问题