发现什么属性导致循环引用错误

发布于 2024-10-22 19:40:31 字数 107 浏览 2 评论 0原文

我正在尝试反序列化一个休眠对象。由于某种原因,我收到循环引用错误。问题是我无法从中找出导致错误的属性。我已经用 [ScriptIgnoreAttribute] 标记了所有连接的类,但仍然没有任何结果。

I am trying to deserialize an nhibernate object. From some reason I am getting a circular reference error. The problem is that I cannot figure from that what property is causing the error. I've marked all connected classes with the [ScriptIgnoreAttribute], and still nothing.

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

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

发布评论

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

评论(1

沉溺在你眼里的海 2024-10-29 19:40:31

我建议您避免将模型对象传递给视图。相反,您应该定义一个专门针对视图需求定制的视图模型,并且该模型仅包含必要的属性。然后在控制器中,您可以在模型和视图模型之间进行映射。例如:

public ActionResult Foo()
{
    SomeModel model = _repository.GetModel();
    SomeViewModel viewModel = Mapper.Map<SomeModel, SomeViewModel>(model);
    return Json(viewModel);
}

这样您就不再需要担心循环引用,因为您可以完全控制视图模型,并且您将只公开视图所需的内容。

I would recommend you to avoid passing your model objects to the view. You should instead define a view model which is specifically tailored to the needs of the view and which would contain only the necessary properties. Then in the controller you could map between the model and the view model. For example:

public ActionResult Foo()
{
    SomeModel model = _repository.GetModel();
    SomeViewModel viewModel = Mapper.Map<SomeModel, SomeViewModel>(model);
    return Json(viewModel);
}

This way you no longer have to worry about circular references as you have total control of your view models and also you would be exposing only what is needed by the view.

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