System.StackOverflowException 未处理(MVC 模型绑定)
当我使用 Model Binder 发回表单时,我开始收到此错误。 为了测试这个问题,我将回发减少到模型的一个字符串属性,但仍然出现溢出错误。 谁能建议什么会导致这种情况?
更新 该问题似乎与模型中的外键属性有关。 如果删除此键,则绑定有效。 如何进行绑定并包含外键关系?
I started getting this error when posting the form back with Model Binder. To test the problem I reduced the postback to one string property of the model but i still get the overflow error. Can anyone suggest what would cause this?
UPDATE
The problem appears to be related to the property in the model that is a foreign key. If this key is removed, the binding works. How can I do the binding and include the foreign key relationship?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过几种方法解决这个问题。 一种方法是尝试这样的事情。
这告诉模型绑定器不要尝试绑定类别(FK 属性)。 这是一个已知问题,MVC 团队已针对 RC 修复了该问题。
您还可以将排除列表传入 UpdateModel/TryUpdateModel 以及添加 Bind 属性的任何位置。
You can fix this a few ways. One way is to try something like this.
This tells the model binder to not try to bind the Category (FK property). This is a known issue and the MVC team has already fixed it for RC.
You can also pass in an exclusion list into UpdateModel/TryUpdateModel and any place you add a Bind attribute.
堆栈溢出通常是由于无限递归造成的。 查看堆栈跟踪,看看是否一遍又一遍地看到相同的函数(或函数组)。 这表明递归函数永远不会达到其基本情况。
A stack overflow is usually due to infinite recursion. Look through the stack trace and see if you see the same function (or group of functions) over and over again. That would indicate that a recursive function is never reaching its base case.