StackoverflowException with ASP.NET MVC
I got this strange Stackoverflow exception today in my MVC project. I have made some modifications to my data model and all of a sudden I got a stack overflow exception when I was submitting data via a form.
I started googling about it and found this thread on the asp.net message board. It turns out that the Default model binder was causing this. The model binder is basically what makes ASP.NET MVC able to automatically bind form post values to your object. You probably know it to some degree if you reading this.
Anyway, to solve the problem you should declare what fields you want to include in the binding by adding an attribute like this. This way the model binder won’t have to deal with the properties that you do not handle in some way.
public ActionResult Ask([Bind(Prefix="question",Include="Text,Title")]Question question)
According to the post in the forums, this is a bug that will be fixed in the next release of the MVC framework. Now back to work!
Read more about both model binders and the bind attribute at Scott Guthries blog post about the beta.