System.Web.Mvc.HtmlHelper <ModelName> does not contain a definition for

I am trying to use Steve Sanderson 's blog post about changing a variable length list. I installed the DLL through the NuGet package manager and made sure that the namespace is in the Views/web.config . However, I see the following error when I try to write stat using .

 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()); } 
+6
source share
3 answers

Please try closing and reopening the solution for changes that will be selected by the editor. After that I do not get an error

System.Web.Mvc.HtmlHelper does not contain a definition for "BeginCollectionItem" and there is no extension for the method "BeginCollectionItem" that takes the first argument of the type "System.Web.Mvc.HtmlHelper" maybe (you did not specify a usage directive or an assmebly link

+7
source

This is the third library from Steve Sanderson, which you must install first from https://www.nuget.org/packages/BeginCollectionItem/ :

 Install-Package BeginCollectionItem 
+3
source

This is a hit in the dark, but did you try to remove the index specifier [i]? As far as I know, you do not need to use it when using the BeginCollectionItem helper. It generates a unique index.



Here are some more resources on the helper that I found useful:

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 with reference to the authorโ€™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> } 
+1
source

All Articles