0

在我的 ASP MVC 3 站点中,我正在尝试使用来自Steve Sanderson 的博客文章BeginCollectionItem的dll 。我的部分视图是这样设置的

@model Monet.Models.DropDownValues

@using (HtmlHelpers.BeginCollectionItem("drop"))
{
    @Html.HiddenFor(model => model.Field)
    @Html.HiddenFor(model => model.DisplayPage)

    <div class="editor-label">
        @Html.LabelFor(model => model.AllowedValue)
    </div>
    <div class="label-field">
        @Html.EditorFor(model => model.AllowedValue)
        @Html.ValidationMessageFor(model => model.AllowedValue)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.DisplayValue)
    </div>
    <div class="label-field">
        @Html.EditorFor(model => model.DisplayValue)
        @Html.ValidationMessageFor(model => model.DisplayValue)
    </div>
}

但是,即使BeginCollectionItem在命名空间下显示为选项HtmlHelpers,我也会收到以下错误:

'HtmlHelpers.BeginCollectionItem' is a 'namespace', which is not valid in the given context

我相信我在位于 Views 文件夹中的 web.config 中正确设置了命名空间,但是我对 ASP MVC 比较陌生,所以不是 100%

  <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
  </sectionGroup>
</configSections>
<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="HtmlHelpers.BeginCollectionItem" />
    </namespaces>
  </pages>
</system.web.webPages.razor>
4

1 回答 1

6

请务必重建您的项目并重新启动 Visual Studio,否则 Web.config 中的更改将不会生效!请参阅此博客: http: //blog.craigtp.co.uk/post/Intellisense-Web-Extensions-Razor-Views-in-ASPNET-MVC-3.aspx

于 2013-06-13T09:25:57.600 回答