How to show server errors in the editing form when insert/update fails on server?

Hello
I have a Grid in the ExternalFormTemplate editing mode, with UpdateURL and InsertURL callbacks. How do I show server errors in the ExternalForm template when the callback fails on server?
I have tried an Action like this

public ActionResult CreateCallback(GridItemViewModel value)
{
var err = new {key="Name", errors=new[] {"Name error"}};
var errm = new List<object> { err };
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return new JsonResult
{
Data = errm, JsonRequestBehavior=JsonRequestBehavior.AllowGet
};
}

which correctly triggers ActionFailure event on the client, but, when the ActionFailure event is received, the editing form is already closed.

I have looked at the
https://www.syncfusion.com/kb/6817/how-to-perform-server-side-validation-in-grid
https://www.syncfusion.com/kb/5170/how-to-display-custom-error-message-on-ajax-action-failture
https://www.syncfusion.com/forums/118649/how-to-bind-modelstate-error-to-sync-fusion-grid-for-inline-editing-updating

but I don't want to use separate validation ajax calls, popups/alerts, and I'd rather not build my own HTML to show errors.

So, is it possible to prevent closing the editing form in the case of insert/update error, or, even better, somehow bind the validation errors from the server to the fields in the editing form, something like

@Html.ValidationMessageFor

in the pure MVC?



Thanks, Tom


5 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team March 19, 2018 12:57 PM UTC

Hi Tom, 

Thanks for contacting Syncfusion Support. 

We have checked your query and we can reproduce your reported problem at our end. If you want to perform serverside validation, we have already discussed how to perform serverside validation in our Syncfusion Knowledge base.  

Please refer to the KB link:- 

If you are expecting other than this, please share us further details. 

Regards, 

Farveen sulthana T 




TT Tomislav Tustonic March 19, 2018 05:54 PM UTC

Hello
Hm, sorry, this doesn't answer my question.
My question is not 'how to perform server side validation', the question is 'how to show server errors in the editing form when insert/update fails on server'.
I know how to perform a server validation, and I actually quoted the KB article as the one I have read and which doesn't answer my problem.
So, again, is there a way to show server side validation in the editing form in ExternalFormTemplate mode, without using separate ajax validation callback (this means that when I try to create/update an item, I receive all the errors in the case of failure, see example in the original question), and on the same editing form.
Perhaps it could be done by preventing closing the editing form in the case of server validation errors, or some other mechanism.

Thanks, Tom


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team March 20, 2018 02:42 PM UTC

Hi Tomislav, 

We can reproduce your reported problem External Form get closed and we have logged this as bug Task “External EditForm get closed while ActionFailure event triggers” and the fix for this issue will be available on 2018 Volume 1 Service Pack 2.  

To workaround this, we have achieved your requirement preventing the Edit Form from being closed using ActionFailure event. In the ActionFailure event of the Grid, we have made the EditForm to display. 

Please refer to the code example:- 

<script> 
      function failure(args) { 
           $("#" + this._id + "_externalEdit").css("display", "block"); 
 
                    
      } 
 </script> 

Please get back to us if you need any further assistance. 

Regards, 

Farveen sulthana T 



TT Tomislav Tustonic March 21, 2018 09:45 PM UTC

Thanks
This seems to work OK.

Cheers, Tom


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team March 22, 2018 12:53 PM UTC

  
Hi Tom, 

Thanks for your update. Please get back to us if you need any further assistance. 

Regards, 

Farveen sulthana T 


Loader.
Up arrow icon