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

How to override the default error message of the edit client event

2 Answers 43 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.
Ronald
Top achievements
Rank 1
Ronald asked on 10 Aug 2011, 08:59 PM
Hi,

I'm working with an MVC Grid binded to web services.
Some times, when I edit an item an error "which I'm expecting" occur.

I would like to override the default error message to show some friendly message, is this possible?

I saw on the documentation the onError event, but it says that this event only fires on binding.

The OnError event is raised when there is an error during databiding.

Thanks


 

2 Answers, 1 is accepted

Sort by
0
Jatin
Top achievements
Rank 1
answered on 11 Aug 2011, 04:05 AM
If the error is related to model you can use ModelState.AddModelError() and then provide for Html.ValidationMessageFor() in your view as usual. If the error is not related to model, then you can use the grids "onError" callback and act accordingly. Here is what I have used in my project.

//The View
<!-- in grid -->
                .ClientEvents(clientEvents => { clientEvents.OnEdit("onGridEdit");
                                                clientEvents.OnSave("onGridSave");
                                                clientEvents.OnLoad("onGridLoad");
                                                clientEvents.OnDataBound("onGridDataBound");
                                                clientEvents.OnError("onGridError");}) //Use these for custom errors
<!-- in Javascript -->
 
    function onGridError(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();
            }
        }
        $('#imgSaveLoading').hide();
    }

//In Controller
if (Your Exception) {
      Response.StatusCode = 500;
      if (Response.StatusCode == 500)
          return Content("Edit Error Occurred"); //Your custom message here
}

Hope it helps.
regards Nirvan
0
Ronald
Top achievements
Rank 1
answered on 11 Aug 2011, 04:26 PM
Thanks for your help.
It works.
Tags
Grid
Asked by
Ronald
Top achievements
Rank 1
Answers by
Jatin
Top achievements
Rank 1
Ronald
Top achievements
Rank 1
Share this question
or