This is a migrated thread and some comments may be shown as answers.

onError event

0 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bill
Top achievements
Rank 2
Bill asked on 23 Feb 2013, 08:18 PM
When exactly does the onError event fire for the grid?

I want to know if what I have is sufficient for any errors that occur in my Controller. In my .Layout_cshtml page, I have the below code snippet...

I want to make sure that if an error occurs inside the Catch block, it will display (via the code in the _Layout.cshtml page).

In my controller, inside the Catch, I don't have anything.

What if I have an error with the Model? Will this automatically display as is or do I need to capture the ModelState error (which I know how to do) in the Controller and spit out an alert message here....

In my View, I have the followng:
.ClientEvents(ev => ev.OnError("error_handler"))

.Layout_cshtml page:
<script type="text/javascript">
            function error_handler(e) {
                if (e.errors) {
                    var message = "Errors:\n";
                    $.each(e.errors, function (key, value) {
                        if ('errors' in value) {
                            $.each(value.errors, function () {
                                message += this + "\n";
                            });
                        }
                    });
                    alert(message);
                }
            }
        </script>
Tags
Grid
Asked by
Bill
Top achievements
Rank 2
Share this question
or