System.Web.Mvc.HtmlHelper&LT;&MODELNAME GT;不包含一个定义 [英] System.Web.Mvc.HtmlHelper<ModelName> does not contain a definition for
问题描述
我想使用的史蒂夫·桑德森的博客文章有关编辑可变长度的名单。我已经安装了通过的NuGet包管理器的DLL,并确保该命名空间是在查看/ web.config中
文件。不过,我下面的错误,当我试图写的使用
说明书。
System.Web.Mvc.HtmlHelper&LT; Monet.Models.AgentTransmission&GT;不包含一个定义
对于BeginCollectionItem',没有扩展方法'BeginCollectionItem接受第一
类型的参数'System.Web.Mvc.HtmlHelper&LT; Monet.Models.AgentTransmission&GT;'可能
(是否缺少using指令或assmebly参考
查看/ Web.config中
&LT;&命名空间GT;
&LT;添加命名空间=System.Web.Mvc/&GT;
&LT;添加命名空间=System.Web.Mvc.Ajax/&GT;
&LT;添加命名空间=System.Web.Mvc.Html/&GT;
&LT;添加命名空间=System.Web.Routing/&GT;
&LT;添加命名空间=HtmlHelpers.BeginCollectionItem/&GT;
&LT; /命名空间&GT;
局部视图(更新)
@model Monet.Models.AgentRelationship codeS@using(Html.BeginCollectionItem(AgentRelationship codeS))
{
&所述; TR&GT;
&LT; TD&GT; @ Html.EditorFor(型号=&GT; model.EffectiveDate,NullableDate,新{@class =相对codeDate2})LT; / TD&GT;
&LT; TD&GT; @ Html.EditorFor(型号=&GT; model.RelationshipId,NullableDate,新{@class =relDist code1,最大长度= 3})LT; / TD&GT;
@ Html.HiddenFor(型号=&GT; model.ID)
@ Html.HiddenFor(型号=&GT; model.Rel codeOrdinal)
&LT; / TR&GT;
}
控制器(以防万一)
使用系统;
使用System.Collections.Generic;
使用System.Configuration;
使用System.Data这;
使用System.Data.Entity.Validation;
使用System.Diagnostics程序;
使用System.IO;
使用System.Linq的;
使用System.Net;
使用的System.Reflection;
使用System.Runtime.Serialization;
使用System.Text;
使用System.Transactions的;
使用的System.Web;
使用System.Web.Mvc;
使用System.Web.Routing;
使用的System.Xml;
使用Monet.MonetToDss;
使用Monet.Common;
使用Monet.Models;
使用Monet.ViewModel;
使用HtmlHelpers.BeginCollectionItem;公众的ViewResult NewRelationship code()
{
返回视图(AddRelationship codePartial,新AgentRelationship codeS());
}
请尝试关闭并重新打开了由编辑器拿起变化的解决方案。这样做,我没有得到错误后
System.Web.Mvc.HtmlHelper不
包含BeginCollectionItem'没有扩展名的定义
方法BeginCollectionItem接受式的第一个参数
System.Web.Mvc.HtmlHelper可能是
(是否缺少using指令或assmebly参考
块引用>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 theusing
statment.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()); }
解决方案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&LT;&MODELNAME GT;不包含一个定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!