我做了一个小项目来理解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
根据我的理解,重新安装后,SharedPreferences数据不应该持续存在.我已经相应地编写了我的应用程序的逻辑.
但是,在Android Studio中的模拟器上使用测试,即使重建并重新安装应用程序后,我也看到SharedPreferences仍然存在.即使我关闭并重新启动模拟器,也会发生这种情况.
谁能解释这个(貌似)奇怪的行为?