I am trying to use Steve Sanderson's blog post about editing a variable length list. I've installed the dll via the NuGet package manager and made sure that the namespace is in the Views/web.config
file. However, I the following error when I attempt to write the using
statment.
我正在尝试使用Steve Sanderson关于编辑可变长度列表的博客文章。我已经通过NuGet包管理器安装了dll,并确保命名空间位于Views / web.config文件中。但是,当我尝试编写使用语句时,我出现以下错误。
System.Web.Mvc.HtmlHelper<Monet.Models.AgentTransmission> does not contain a definition
for 'BeginCollectionItem' and no extension method 'BeginCollectionItem' accepting a first
argument of type 'System.Web.Mvc.HtmlHelper<Monet.Models.AgentTransmission>' could be
found (are you missing a using directive or an assmebly reference
Views/Web.config
<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>
Partial View (updated)
部分视图(更新)
@model Monet.Models.AgentRelationshipCodes
@using (Html.BeginCollectionItem("AgentRelationshipCodes"))
{
<tr>
<td>@Html.EditorFor(model => model.EffectiveDate, "NullableDate", new { @class = "relCodeDate2" })</td>
<td>@Html.EditorFor(model => model.RelationshipId, "NullableDate", new { @class = "relDistCode1", maxlength = 3 })</td>
@Html.HiddenFor(model => model.ID)
@Html.HiddenFor(model => model.RelCodeOrdinal)
</tr>
}
Controller (just in case)
控制器(以防万一)
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Entity.Validation;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Transactions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Xml;
using Monet.MonetToDss;
using Monet.Common;
using Monet.Models;
using Monet.ViewModel;
using HtmlHelpers.BeginCollectionItem;
public ViewResult NewRelationshipCode()
{
return View("AddRelationshipCodePartial", new AgentRelationshipCodes());
}
4 个解决方案
#1
7
Please try to close and re-open the solution for the changes to be picked up by editor. After doing that I don't get the error
请尝试关闭并重新打开解决方案,以便编辑器选择更改。在这之后我没有得到错误
System.Web.Mvc.HtmlHelper does not contain a definition for 'BeginCollectionItem' and no extension method 'BeginCollectionItem' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assmebly reference
System.Web.Mvc.HtmlHelper不包含'BeginCollectionItem'的定义,并且没有可以找到接受类型'System.Web.Mvc.HtmlHelper'的第一个参数的扩展方法'BeginCollectionItem'(你是否缺少using指令或者可以参考
#2
3
It is a third party library by Steve Sanderson, which you have to install first from https://www.nuget.org/packages/BeginCollectionItem/:
它是Steve Sanderson的第三方库,您必须首先从https://www.nuget.org/packages/BeginCollectionItem/安装:
Install-Package BeginCollectionItem
#3
1
This is a stab in the dark, but have you tried removing the index specifier [i]? You shouldn't need one when using the BeginCollectionItem helper, as far as I recall. It generates the unique index itself.
Here are a couple more resources on the helper that I found useful:
这是在黑暗中刺伤,但你尝试删除索引说明符[i]?据我所知,在使用BeginCollectionItem助手时你不应该需要一个。它自己生成唯一索引。以下是我发现有用的帮助器上的更多资源:
http://ivanz.com/2011/06/16/editing-variable-length-reorderable-collections-in-asp-net-mvc-part-1/ http://justmycode.blogspot.com/2012/07/learning-mvc-editing-variable-length.html
Update: Example in reference to asker's comment
更新:参考提问者评论的示例
@model Monet.Models.AgentRelationshipCodes
@using (Html.BeginCollectionItem("AgentRelationshipCodes")) @*error displays here*@
{
<tr>
<td>@Html.EditorFor(m => Model.EffectiveDate, "NullableDate", new { @class = "relCodeDate2" })</td>
<td>@Html.EditorFor(m => Model.RelationshipId, "NullableDate", new { @class = "relDistCode1", maxlength = 3 })</td>
@Html.HiddenFor(m => Model.ID)
@Html.HiddenFor(m => Model.RelCodeOrdinal)
</tr>
}
#4
0
I needed to add
我需要补充一下
<add namespace="HtmlHelpers.BeginCollectionItem" />
to the namespaces in the web.config of the Views folder. Mine was in an "Areas" folder so I needed to add it in the Views folder there.
到Views文件夹的web.config中的命名空间。我在“区域”文件夹中,所以我需要将它添加到Views文件夹中。
You can also add a using statement right on the view instead, but then you have to remember to add it to each view.
您也可以在视图上添加using语句,但是您必须记住将其添加到每个视图中。
#1
7
Please try to close and re-open the solution for the changes to be picked up by editor. After doing that I don't get the error
请尝试关闭并重新打开解决方案,以便编辑器选择更改。在这之后我没有得到错误
System.Web.Mvc.HtmlHelper does not contain a definition for 'BeginCollectionItem' and no extension method 'BeginCollectionItem' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assmebly reference
System.Web.Mvc.HtmlHelper不包含'BeginCollectionItem'的定义,并且没有可以找到接受类型'System.Web.Mvc.HtmlHelper'的第一个参数的扩展方法'BeginCollectionItem'(你是否缺少using指令或者可以参考
#2
3
It is a third party library by Steve Sanderson, which you have to install first from https://www.nuget.org/packages/BeginCollectionItem/:
它是Steve Sanderson的第三方库,您必须首先从https://www.nuget.org/packages/BeginCollectionItem/安装:
Install-Package BeginCollectionItem
#3
1
This is a stab in the dark, but have you tried removing the index specifier [i]? You shouldn't need one when using the BeginCollectionItem helper, as far as I recall. It generates the unique index itself.
Here are a couple more resources on the helper that I found useful:
这是在黑暗中刺伤,但你尝试删除索引说明符[i]?据我所知,在使用BeginCollectionItem助手时你不应该需要一个。它自己生成唯一索引。以下是我发现有用的帮助器上的更多资源:
http://ivanz.com/2011/06/16/editing-variable-length-reorderable-collections-in-asp-net-mvc-part-1/ http://justmycode.blogspot.com/2012/07/learning-mvc-editing-variable-length.html
Update: Example in reference to asker's comment
更新:参考提问者评论的示例
@model Monet.Models.AgentRelationshipCodes
@using (Html.BeginCollectionItem("AgentRelationshipCodes")) @*error displays here*@
{
<tr>
<td>@Html.EditorFor(m => Model.EffectiveDate, "NullableDate", new { @class = "relCodeDate2" })</td>
<td>@Html.EditorFor(m => Model.RelationshipId, "NullableDate", new { @class = "relDistCode1", maxlength = 3 })</td>
@Html.HiddenFor(m => Model.ID)
@Html.HiddenFor(m => Model.RelCodeOrdinal)
</tr>
}
#4
0
I needed to add
我需要补充一下
<add namespace="HtmlHelpers.BeginCollectionItem" />
to the namespaces in the web.config of the Views folder. Mine was in an "Areas" folder so I needed to add it in the Views folder there.
到Views文件夹的web.config中的命名空间。我在“区域”文件夹中,所以我需要将它添加到Views文件夹中。
You can also add a using statement right on the view instead, but then you have to remember to add it to each view.
您也可以在视图上添加using语句,但是您必须记住将其添加到每个视图中。