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

Display error page

I have a grid that has defined defined CRUD operations on it. I am using the built-in Exception middleware to handle errors. However, the error page is not displayed when the controller's CREATE method throws an exception. However, the error page is displayed when an exception is thrown from the READ method. How do I force the CREATE controller to display the error page. Below is my code:

HTML

 <div class="col-md-4 col-md-offset-4">

                <ej-grid id="grd" allow-filtering="true" allow-paging="true" enable-header-hover="true" allow-sorting="true">

                    <e-edit-settings allow-adding="true" allow-editing="true"/>

                    <e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"add","edit","update","cancel"}' />  

                    <e-datamanager json="@Model" insert-url="/Home/Create" update-url="/Home/Update" adaptor="remoteSaveAdaptor" />

                    <e-columns>

                        <e-column header-text="Id" field="Id" is-primary-key="true" is-identity="true" visible="false" />

                        <e-column header-text="Name" field="Name" />

                    </e-columns>

                </ej-grid>

            </div>

Controller

 public class HomeController : Controller
    {
       
        public IActionResult Read()
        {
              throw new Exception("Test bad request.");     //Error page displayed.
        }

        public ActionResult Create([FromBody] CRUDModel<MyType> myObject)
        {
              throw new Exception("Test bad request.");           //Error page not displayed.
        }

    }

7 Replies

KK Karthick Kuppusamy Syncfusion Team September 21, 2016 03:49 PM UTC

Hi Llewelyn, 

Thanks for Contacting Syncfusion Support. 

We have analyzed your requirement and we can achieve the requirement through the action failure event of the grid. 

We can call the “action Failure” event form the server side and we can able to redirect the custom page. 

Please find the code example. 

 
<ej-grid id="grd" allow-filtering="true" allow-paging="true" e-actionFailure="actionFailure" //action failure evnt 
 
enable-header-hover="true" allow-sorting="true"> 
 
 
                    <e-datamanager json="@Model" insert-url="/Home/Create" update-url="/Home/Update" adaptor="remoteSaveAdaptor" /> 
 
                    <e-columns> 
 
                        ………. 
                    </e-columns> 
 
</ej-grid> 
     <script> 
         function actionFailure(args) { 
             window.location = "https://help.syncfusion.com/";//redirect to the custom page 
         } 
     </script> 


   
public class HomeController : Controller 
        { 
 
            public IActionResult Read() 
            { 
                throw new Exception("Test bad request.");      
 
             
            public ActionResult Create([FromBody] CRUDModel<MyType> myObject) 
            { 
                throw new Exception("Test bad request.”)//call the action Failure event of the grid 
        } 
 
        } 


Please find the UG Link for your reference. 

Please let us know if you have any concern. 

Regards, 
K.Karthick 



LJ Llewelyn Jones September 21, 2016 10:38 PM UTC

The issue persists.. 
This solution below seems to not inline with Error handling technique suggested by Microsoft here
I want to use the Error handling middleware as suggest by Microsoft.

Are you saying that the throw Exception below should be enough to trigger the action failure event?
  
public ActionResult Create([FromBody] CRUDModel<MyType> myObject) 
            { 
                throw new Exception("Test bad request.”)//call the action Failure event of the grid 
        } 


KK Karthick Kuppusamy Syncfusion Team September 23, 2016 03:35 PM UTC

Hi Llewelyn, 

Yes.Through the exception in server side is enough to trigger the action failure event of the grid.we can get the error list in client side and we can display. 

Are you want to display the middle ware page expection for every failure or only the crud page expection.Could you please share the more details on this requirement. 

Regards, 
K.Karthick 



LJ Llewelyn Jones September 23, 2016 06:56 PM UTC

As per Microsoft suggestion, the middleware should handle routing to error page when an exception is thrown. This configuration is done in the Startup class. 
Your solution seems require explicitly redirect to error page on client but I want the middleware to take care of that. 
My current project functionality allows automatic routing to error page if exception occurs in the view but it does not route to error page if exception occurs in the controller.


KK Karthick Kuppusamy Syncfusion Team September 27, 2016 01:08 PM UTC

Hi Llewelyn, 
 
We have analyzed your requirement and we are not able to redirect to the middleware error page from the server side CRUD operation controller action method, because we are using the ajax request(partial post)for the following CRUD operation. So redirection to other action controller method is not possible during the partial post 
 
1.Insert  
 
2.Update 
 
3.Delete 
 
Hence we suggested you to use the ActionFailure client side event to handle the serverside exception and from that event we are able to redirect to the custom page. The necessary failure information has been obtained in the ActionFailure event. Please refer the below UG link to know the arguments that has been obtained in the event. 
 
 
 
Please let us know if you have any concern. 
 
Regards, 
K.Karthick. 
 



LJ Llewelyn Jones September 28, 2016 01:16 PM UTC

Thanks for the update.  I would like if the ability to call the middleware from controller is implemented in the grid.


KK Karthick Kuppusamy Syncfusion Team October 1, 2016 02:16 AM UTC

Hi Llewelyn, 

We have analyzed your requirement and we suggest you to use the formpost by cancel the default ajax post(half post) in actionbegin event for update action and updating the grid values with formpost(fullpost). 

Please find the code example. 

<ej-grid id="grd" allow-filtering="true" allow-paging="true" e-actionBegin="actionbegin" //action begin 
  
enable-header-hover="true" allow-sorting="true">  
  
  
                    <e-datamanager json="@Model" insert-url="/Home/Create" update-url="/Home/Update" adaptor="remoteSaveAdaptor" />  
  
                    <e-columns>  
  
                        ……….  
                    </e-columns>  
  
</ej-grid>  
 
<script> 
    function actionbegin(args) { 
        if (args.requestType == "save") { 
            args.cancel = true;//cancel the default ajaxpost 
            var data = []; // create array here 
            $.each(args.data, function (index,value) { 
                data.push(value); //push values here 
            }); 
            var formlength = $(".e-field").length; 
            for (i = 0; i < formlength; i++) { 
               $(".e-field").eq(i).attr('value',data[i]);//assign the all values to the form elements 
            } 
            $("#GridEditForm").attr({ action: "/Home/Create ", method: "POST" }); 
            $("#GridEditForm").submit();//call the formpost 
        } 
        } 
</script> 


 
    
public class HomeController : Controller  
        {  
  
            public IActionResult Read()  
            {  
                throw new Exception("Test bad request.");       
  
              
            public ActionResult Create([FromBody] CRUDModel<MyType> myObject)  
            {  
                 
            . 
            . 
            . 
           throw new Exception("Test bad request.”)//exception  
        }  
  
        }  

Using the formpost(fullpost) we can easily redirect to the middleware exception page. 

Regards, 
K.Karthick. 


Loader.
Live Chat Icon For mobile
Up arrow icon