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

Empty Error Message popup after successful BatchSave

2 Answers 74 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.
Shawn
Top achievements
Rank 2
Shawn asked on 13 Apr 2012, 12:15 AM
I'm implementing the batch edit process using the sample provided for this in the demo.  It works fine for addition of new records, but after saving an update or a delete, even though the save to the database actually happened successfully, the Grid_onError event is raised and executed.  It pops up a message box, the only text of which is "Errors: "; it lists no errors though.  So I click OK to dismiss the alert. Now the problem I have with this is that it does not clear the "edited" state of the grid as it would after a successful save!  The edited fields still have their red corner flag on.  If I click the refresh button on the bottom left of the grid, it warns me that I will lose data (to which I just click OK), and then the grid is refreshed with the correctly-updated data from the database.
Please advise as to why I am experiencing this behavior.
Thank you kindly for a great product.
--Shawn.

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 16 Apr 2012, 02:59 PM
Hi,

 This could happen if there are any model state errors. The OnError event will be raised in this case. You can check if this is the case like this:

function Grid_onError(e) {
    if (e.textStatus == "modelstateerror") {
         alert("Model state errors");
    }
}

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Shawn
Top achievements
Rank 2
answered on 02 May 2012, 12:22 PM
Thanks for the answer.  Could you please tell me though what property of the "e" parameter I could use to get at the actual error message?  For that matter, is the structure of the "e" parameter documented anywhere, then I could perhaps figure this out myself?  Thanks a mil'.

EDIT: Actually nevermind the above...I found it in the online documentation.  However, this does lead to a different question:
I put this code into my Grid_OnError event handler:
console.log("These are your errors:");
console.log(args.modelState);
console.log("Those were your errors.");

This returns the following using Firebug console:
These are your errors:

If I drill down into the Object that is output, I see the following:
updated[0].EntityKey.EntityKeyValues
Object { errors=[1]}
errors [""]
0 ""
updated[1].EntityKey.EntityKeyValues
Object { errors=[1]}
errors [""]
0 ""

The fact that there are two Object instances makes sense, as I had made changes to two different rows in my grid.  But what doesn't make sense to me is why the object is returning empty error strings, thereby causing the Grid_OnError event to be raised and handled.  Recall in my initial post, the "Save Changes" button is indeed correctly saving my changes to the database.  So why these empty errors?  Please help.

EDIT Again:
OK I found the problem by putting a breakpoint in my controller method that gets called on saving grid changes.  I checked ModelState and found that one of properties has an exception.  Interestingly, the exception had to do with EntityKeyValues being empty, yet the ErrorMessage property was an empty string (this is probably what translated into the empty error messages in my initial post.  Since all was saving fine to the database, I have just side-stepped the problem by calling ModelState.Clear just before returning to the View.  Now all is working as expected.
Tags
Grid
Asked by
Shawn
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Shawn
Top achievements
Rank 2
Share this question
or