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.
Unfortunately, activation email could not send to your email. Please try again.

Multiple delete and server error message

Thread ID:

Created:

Updated:

Platform:

Replies:

123354 Mar 9,2016 12:51 PM Mar 24,2016 01:34 AM ASP.NET MVC 5
loading
Tags: Grid
Omar Muscatello
Asked On March 9, 2016 12:51 PM

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?



Ragavee U S [Syncfusion]
Replied On March 10, 2016 06:53 AM

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.

Omar Muscatello
Replied On March 16, 2016 06:37 AM

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?

Ragavee U S [Syncfusion]
Replied On March 17, 2016 08:09 AM

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.

Omar Muscatello
Replied On March 23, 2016 04:07 AM

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.

Ragavee U S [Syncfusion]
Replied On March 24, 2016 01:34 AM

Hi Omar,

Thanks for your update.

We are happy that your requirement is achieved.

Regards,
Ragavee U S.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;