删除列表项时更新模型错误

发布于 2024-07-10 18:56:00 字数 224 浏览 9 评论 0原文

我有一个编辑页面来编辑一些信息。 页面填充了一个复杂的对象。 该对象的属性之一是通用列表。

如果我只是编辑信息并保存,updatemodel 就可以正常工作。 如果我从列表中删除(我使用 jquery 删除表单元素客户端)某些内容,则 updatemodel 将失败并显示“对象未设置为实例”。

我猜更新模型期望列表保持相同的长度或其他内容,但找不到有关此的任何信息,有什么想法吗?

I have an edit page to edit some info. the page fills a complex object. one of the properties of this object is a generic list.

If I just edit information and save, updatemodel works fine. if i remove (I do this using jquery to remove the form elements client side) something from the list the updatemodel fails with an "object not set to an instance".

I guess the update model is expecting the list to remain of the same length or something but cannot find any information about this, any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠北森屋 2024-07-17 18:56:00

好的,解决了 jquery 删除例程上的问题(当然是程序员错误),我删除了所有元素,除了模型绑定器用于列表的隐藏字段:(

OK, figured out the problem (and it was of course programmer error) on the jquery remove routine I had removed all the elements EXCEPT the hidden field that the model binder uses for lists :(

夕色琉璃 2024-07-17 18:56:00

模型绑定器将尝试映射您的复杂对象属性,并从以下位置检索数据:
1) 来自 RouteData 的值
2) URI查询字符串
3)请求表单提交
检查这个地方,看看为什么你的财产是空的。 如果您要删除表单元素,您的资源将不会收到任何数据。
一些信息此处 以及 Scott Hanselman 此处 进行的错误分析。

The model binder will try to map your complex object properties retrieving data from:
1) values from the RouteData
2) URI query string
3) request form submission
Check this places to see why your property is null. If you're deleting your form elements your property will not receive any data.
Some info here and a bug analysis by Scott Hanselman here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文