MVC3 无法识别 Razor 视图中的 MvcContrib 命名空间 [英] MVC3 doesn't recognize MvcContrib namespace in Razor View

查看:11
本文介绍了MVC3 无法识别 Razor 视图中的 MvcContrib 命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MvcContrib 的 Html.Pager() 对某些内容进行分页,但我的 razor 视图无法引用正确的命名空间.

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

控制器没问题:

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

@Html.Pager((IPagination)Model)

我通过 NuGet 安装了 MvcContrib.我尝试将 MvcContribMvcContrib.UIMvcContrib.UI.Html 命名空间添加到 代码> 在 web.config 没有运气.我错过了什么吗?

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?

推荐答案

与 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)

这篇关于MVC3 无法识别 Razor 视图中的 MvcContrib 命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆