且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MVC3不承认MvcContrib命名空间的Razor视图

更新时间:2023-10-10 17:20:22

相反的WebForms,剃刀不使用<命名空间> 在第〜/的web.config 。它使用<&命名空间GT; 〜/查看/ web.config中

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>

和则:

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

或者你也可以在适当的命名空间添加到您的视图,如果你preFER:

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)