tb.deleteRecord("Id", rows[row]);
alert($(args.error.error.responseText).find('i').first().text());
try{
DataContext db = new DataContext();
db.Pazienti.Remove(db.Pazienti.Find(key));
}
catch(Exception ex){
throw new Exception("Errore durante l'eliminazione");
}return Json(true);
[HttpPost] public JsonResult Elimina(int key) {
try { DataContext db = new DataContext(); db.Pazienti.Remove(db.Pazienti.Find(key)); } catch (Exception ex) { throw new Exception("Errore durante l'eliminazione"); } return Json(true); }
Javascript //actionFailure event of the Grid function failure(args) { alert(args.error.responseText); //get the exception message } |
Hi Omar,
Query #1: Is there a better method to delete multiple rows?
We considered this query “Delete multiple rows in Grid” as a feature and a support incident has been created under your account to track the status of this issue. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents
Query #2: Is there a better method to get errors from server?
The actionFailure event will be triggered once an exception occurs at server side data/CRUD operations. In actionFailure event, we can get the exception message and display it using event argument. Please find the code example for more reference.
[HttpPost]
public JsonResult Elimina(int key)
{
try
{
DataContext db = new DataContext();
db.Pazienti.Remove(db.Pazienti.Find(key));
}
catch (Exception ex)
{
throw new Exception("Errore durante l'eliminazione");
}
return Json(true);
}
Javascript
//actionFailure event of the Grid
function failure(args) {
alert(args.error.responseText); //get the exception message
}
Regards,
Ragavee U S.
</system.web><customErrors mode="Off" />...
public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm) { . . . . // if(exception occurs) condition to thrown an exception HttpContext.Response.AddHeader("Exception", "Our Exception message");//add exception message to the response header Response.StatusCode = 404; //set failure in request. . . . . <script type="text/javascript"> function failure(args) { alert(args.error.getResponseHeader('Exception')); } |
Hi Omar,
Thanks for your update.
Since the responseText returns the whole html code in ActionFailure event, we suggest you to add a custom header to response header to store the exception data and retrieve it in the ActionFailure event using the getResponseHeader method of the args.error parameter.
Please refer to the below code example.
public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)
{
. . . .
// if(exception occurs) condition to thrown an exception
HttpContext.Response.AddHeader("Exception", "Our Exception message");//add exception message to the response header
Response.StatusCode = 404; //set failure in request.
. . . .
}
<script type="text/javascript">
function failure(args) {
alert(args.error.getResponseHeader('Exception'));
}
</script>
For your convenience, we have prepared a sample with the above solution which can be downloaded from the below location.
Sample Link: http://www.syncfusion.com/downloads/support/forum/123354/ze/ActionFailure_Sample1676907807
Regards,
Ragavee U S.