Can I use [HandleError] on a Telerik [GridAction]? (Telerik MVC)
I'm using Telerik Extensions for ASP.NET MVC, using Ajax databinding on a grid. I'm using the HandleError attribute on the entire controller class, like so:
[HandleError]
public class MyController : Controller { ...and the error handling works fine in the regular Action methods. However, on the [GridAction] me开发者_StackOverflowthods, such as the one that handles insertion of a new grid record, I can't get around the dang "500 - Internal Server Error" popup that is used by default. I'd like to be able to spit back an exception so the user can see why their record is not being inserted, but the Telerik GridAction methods and HandleError don't seem to want to play together.
Anybody been there and/or done that? Thanks, Dave
I have just used this http://www.telerik.com/community/forums/aspnet-mvc/grid/how-to-return-error-information-to-grid-in-ajax-editing-mode.aspx
Sorted the issue for me.
In fact, I just needed to handle the .OnError event from the grid:
.ClientEvents(events => events
.OnLoad("onLoad")
.OnError("onError")
)
)
<script type="text/javascript">
function onLoad(e) {
$(this).find('.t-no-data td').text('Loading...');
}
function onError(e) {
if (e.textStatus == 'error') {
if (e.XMLHttpRequest.status == "500") {
alert("The server was unable to process your request.\n" + e.XMLHttpRequest.responseText);
e.preventDefault();
}
}
}
</script>
The OnError event will be raised in the following occasions:
- The URL being requested is not found (404 HTTP code)
- Unhandled .NET exception (500 HTTP code)
- ModelState error
- Timeout
精彩评论