We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Multiple delete and server error message

Hello Syncfusion Team,
I want to delete multiple rows from grid.

I'm using this code:

View
$('#myButton').click(function(){
     var rows = tb.getSelectedRows();
     for(var row in rows){
tb.deleteRecord("Id", rows[row]); 
    }
});

function OnActionFailure(args){
alert($(args.error.error.responseText).find('i').first().text());
}

Controller
[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);
}

Is there a better method to delete multiple rows?
Is there a better method to get errors from server?



5 Replies

RU Ragavee U S Syncfusion Team March 10, 2016 11:53 AM UTC

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.


OM Omar Muscatello replied to Ragavee U S March 16, 2016 10:37 AM UTC

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.

Thank you Ragavee U S.

args.error.responseText return a web-page containing the error message. So I use $(args.error.error.responseText).find('i').first().text() to get only the error message.

Also, it works only in debug mode, when Web.config contains

<system.web>
<customErrors mode="Off" />
...
</system.web>

In release it returns html code with generic error message, so I can't extract the error message.

How can I solve this?


RU Ragavee U S Syncfusion Team March 17, 2016 12:09 PM UTC

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.


OM Omar Muscatello replied to Ragavee U S March 23, 2016 08:07 AM UTC

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.

Thank you Ragavee U S, nice solution.


RU Ragavee U S Syncfusion Team March 24, 2016 05:34 AM UTC

Hi Omar,

Thanks for your update.

We are happy that your requirement is achieved.

Regards,
Ragavee U S.

Loader.
Live Chat Icon For mobile
Up arrow icon