How to get exception details from MVC3 ajax call
I use ASP.NET MVC 3 with Razor and Ajax.ActionLink/BeginForm to update Partial Views. When there is a server-side exception, how to get and display exce开发者_JAVA技巧ption details in the browser?
Thanks
You need to do 2 things: first create a filter in which you will set the result in the filterContext with the piece of information you want to display. Second, you will need a piece of client code to handle the response. You can do this via jQuery $.ajaxError.
You could also create a specific controller and a view for more complicated scenarii. This is described here:
http://christopheargento.com/2011/08/18/unifier-les-remontees-dexception-ajax-et-non-ajax-en-asp-net-mvc-3/
It is in french but there is a demo and downloadable code. If you need more information you can ask me.
EDIT: Finally the english version of the article is released: http://blog.christopheargento.net/2012/06/14/unify-exception-handling-between-ajax-and-non-ajax-requests-in-asp-net-mvc/
精彩评论