我做了一个小项目来理解Stephen Muecke的答案:将多次调用的同一部分视图提交给控制器?
几乎一切都有效.javascript在Partial View中添加了新的字段,我可以通过控制器方法为局部视图插入的"temp"值来告诉他们它们与模型绑定.
但是,当我提交新字段时,AddRecord()方法抛出一个异常,表明模型没有被传入("对象引用未设置为对象的实例").
此外,当我查看页面源时,BeginCollectionItem帮助器正在主视图中的表周围插入一个隐藏标记,该标记显示预先存在的记录,但不包括javascript添加的新字段.
我究竟做错了什么?我很擅长这一点,谢谢你的耐心等待!
我的主要观点:
@model IEnumerable<DynamicForm.Models.CashRecipient>
@using (Html.BeginForm("AddDetail", "CashRecipients", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div id="CSQGroup">
</div>
}
<div>
<input type="button" value="Add Field" id="addField" onclick="addFieldss()" />
</div>
<script>
function addFieldss()
{
//alert("ajax call");
$.ajax({
url: '@Url.Content("~/CashRecipients/RecipientForm")',
type: 'GET',
success:function(result) {
//alert("Success");
var newDiv = document.createElement("div");
var newContent = document.createTextNode("Hi there and greetings!");
newDiv.appendChild(newContent);
newDiv.innerHTML = result;
var currentDiv = document.getElementById("div1");
document.getElementById("CSQGroup").appendChild(newDiv);
},
error: function(result) {
alert("Failure");
}
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
我的部分观点:
@model DynamicForm.Models.CashRecipient
@using HtmlHelpers.BeginCollectionItem
@using (Html.BeginCollectionItem("recipients")) …Run Code Online (Sandbox Code Playgroud) javascript asp.net-mvc model-binding asp.net-mvc-partialview begincollectionitem
我正在尝试使用Steve Sanderson的博客文章来编辑我的ASP MVC 3视图中的可变长度列表.项目构建正常,但是每当呈现局部视图时,程序就会出现using(Html.BeginColletionItem()此错误:
AccessViolationException was unhandled
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Run Code Online (Sandbox Code Playgroud)
这是完整例外的屏幕截图

完整的堆栈跟踪如下
at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn)
at Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(Object acceptedSocket)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Run Code Online (Sandbox Code Playgroud)
局部视图
@model Monet.Models.AgentRelationshipCodes
@using (Html.BeginCollectionItem("AgentRelationshipCodes")) @*Exception thrown here*@
{
<tr>
<td>@Html.EditorFor(model => model.EffectiveDate, "NullableDate", new { @class …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc access-violation asp.net-mvc-3 begincollectionitem
我不能在asp.net核心中使用Steve Anderson的BeginCollectionItem.我使用时在部分视图中出错
@using (Html.BeginCollectionItem("Entries"))
{
}
Run Code Online (Sandbox Code Playgroud)
"HtmlHelper"类型在未引用的程序集中定义.您必须添加对程序集'System.Web.Mvc,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'的引用.
是否有另一种方法可以在ASP.net核心中实现BeginCollectionItem的功能?
我正在尝试使用Steve Sanderson关于编辑可变长度列表的博客文章.我已经通过NuGet包管理器安装了dll,并确保命名空间在Views/web.config文件中.但是,当我尝试编写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
Run Code Online (Sandbox Code Playgroud)
查看/ 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>
Run Code Online (Sandbox Code Playgroud)
部分视图(更新)
@model Monet.Models.AgentRelationshipCodes
@using (Html.BeginCollectionItem("AgentRelationshipCodes"))
{
<tr>
<td>@Html.EditorFor(model => model.EffectiveDate, "NullableDate", new { @class = "relCodeDate2" })</td>
<td>@Html.EditorFor(model …Run Code Online (Sandbox Code Playgroud)