views:

790

answers:

2

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?

A: 

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.

Jason Creighton
+1  A: 

You can fix this a few ways. One way is to try something like this.

public ActionResult AddProduct([Bind(Exclude = "Category")]Product product) { }

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.

Chad Moran
thanks for info. ACtually, "Exclude" does not work either.
zsharp
Yes it does. I've ran into the same issue and Exclude fixed it for me. You just have to make sure you exclude all FK properties.
Chad Moran
Exclude still didnt work, so I just Included all the others and it did work. thanks.
zsharp