Ich versuche etwas mit MvcContribs zu paginieren Html.Pager()
, aber meine Rasiereransichten können nicht auf den richtigen Namensraum verweisen.
Controller ist in Ordnung:
using MvcContrib.Pagination;
...
public ActionResult List(int? page)
{
return View(new UserRepository().GetUserList().AsPagination(page ?? 1, 10));
}
Aber die Ansicht kann keinen Sinn machen von:
@using MvcContrib
ODER
@Html.Pager((IPagination)Model)
Ich habe MvcContrib über NuGet installiert. Ich habe versucht, hinzuzufügen MvcContrib
, MvcContrib.UI
und MvcContrib.UI.Html
Namespaces zu <pages><namespaces>
in web.config ohne Glück. Habe ich etwas verpasst?
Antworten:
15 für die Antwort № 1Im Gegensatz zu WebForms verwendet Razor nicht die <namespaces>
Abschnitt in ~/web.config
. Es nutzt die <namespaces>
im ~/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>
und dann:
@model MvcContrib.Pagination.IPagination<SomeViewModel>
@Html.Pager(Model)
oder Sie können auch den richtigen Namespace zu Ihrer Ansicht hinzufügen, wenn Sie bevorzugen:
@model MvcContrib.Pagination.IPagination<SomeViewModel>
@using MvcContrib.UI.Pager
@Html.Pager(Model)
0 für die Antwort № 2
Versuchen Sie nach dem Hinzufügen der MvcContrib.dll-Referenz diesen Code.
@using MvcContrib.UI.Pager
@using MvcContrib.Pagination
@model IPagination
@Html.Pager(Model)
Ich habe MvcContrib Grid Paging gepostet, Filter + MVC3 Razor Beispielartikel zu meinem Blog.