Return StatusCode from CRUD action

Any idea why this code is not working?


I'm handling the error with actionFailure event of the grid:



but it show's me alert message even if the  return StatusCode((int)HttpStatusCode.BadRequest, "Error!"); is not executed.


This is the response.


If I disable everything except

_context.BlagajnaUplIsp.Add(value.Value);
await _context.SaveChangesAsync();
return new JsonResult(value.Value);

then the insert is working.


Any idea?

Thanks!

Bernard.


3 Replies

RR Rajapandi Ravi Syncfusion Team November 15, 2021 12:24 PM UTC

Hi Bernard, 

Greetings from Syncfusion support 

Based on your query we have prepared a sample which was same as your application scenario and try to reproduce your reported problem at our end, but it was unsuccessful. The Insert action was working fine at our end. Please refer the below code example and sample for more information. 

 
public async Task<ActionResult> Insert([FromBody]CRUDModel<Orders> param) 
        { 
            if (param.Value.EmployeeID == 10) 
            { 
                throw new Exception("EmployeeID cannot be 10"); 
            } // Created exception 
            _context.Orders.Add(param.Value); 
            await _context.SaveChangesAsync(); 
            return Json(param.Value); 
 
        } 
 


Regards, 
Rajapandi R 



BJ Bernard Jurlina November 16, 2021 09:52 PM UTC

Thanks Rajapandi R!

I'll try it.


Regards!

Bernard.



RR Rajapandi Ravi Syncfusion Team November 17, 2021 03:29 AM UTC

Hi Bernard, 

Thanks for the update.  

We will wait to hear from you.  

Rajapandi R 



Loader.
Up arrow icon