discover what property is causing a circular reference error
I am trying to deserialize an nhibernate object. From开发者_如何学Go 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.
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.
精彩评论