MVC3 doesn't recognize MvcContrib namespace in Razor View

后端 未结 2 1164
情书的邮戳
情书的邮戳 2021-01-04 10:19

I\'m trying to paginate something with MvcContrib\'s Html.Pager(), but my razor views can\'t reference the right namespace.

Controller is ok:

         


        
相关标签:
2条回答
  • 2021-01-04 11:05

    After adding MvcContrib.dll reference, try this code.

    @using MvcContrib.UI.Pager
    @using MvcContrib.Pagination
    @model IPagination    
    
    @Html.Pager(Model)
    

    I posted MvcContrib Grid paging,filtering + MVC3 Razor sample article to my blog.

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

    Contrary to WebForms, Razor doesn't use the <namespaces> section in ~/web.config. It uses the <namespaces> in ~/Views/web.config:

      <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <namespaces>
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
            <add namespace="MvcContrib"/>
            <add namespace="MvcContrib.UI.Grid"/>
            <add namespace="MvcContrib.UI.Pager"/>
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    

    and then:

    @model MvcContrib.Pagination.IPagination<SomeViewModel>
    @Html.Pager(Model)
    

    or you could also add the proper namespace to your view if you prefer:

    @model MvcContrib.Pagination.IPagination<SomeViewModel>
    @using MvcContrib.UI.Pager
    @Html.Pager(Model)
    
    0 讨论(0)
提交回复
热议问题