更新时间:2023-12-06 12:16:04
与 WebForms 不同,Razor 不使用 ~/web.config
中的
部分代码>.它使用~/Views/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)
或者,如果您愿意,也可以将适当的命名空间添加到您的视图中:
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)