MVC3 doesn't recognize MvcContrib namespace in Razor View
Asked Answered
U

2

11

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

Controller is ok:

using MvcContrib.Pagination;
...
public ActionResult List(int? page)
{
    return View(new UserRepository().GetUserList().AsPagination(page ?? 1, 10));
}

But, the view can't make sense of either:

@using MvcContrib

OR

@Html.Pager((IPagination)Model)

I installed MvcContrib via NuGet. I tried adding MvcContrib, MvcContrib.UI and MvcContrib.UI.Html namespaces to <pages><namespaces> in web.config with no luck. Did I miss something?

Urbana answered 18/3, 2011 at 1:14 Comment(0)
U
15

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)
Unrepair answered 18/3, 2011 at 9:12 Comment(2)
I'll give that a shot--I thought NuGet would have done that automagically.Urbana
@Darin After working with Microsoft's WebGrid I decided to give MvcContrib's grid a chance. So far I like it. Way better with lots of customizable points... The only thing I feel is missing is a more consistent documentation section on the site mvccontrib.codeplex.com/… and better integration with an ASP.NET MVC app when the NuGet package is installed.Freyah
V
0

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.

Verret answered 21/3, 2011 at 4:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.