[DontWrapResult]
[AcceptVerbs(HttpVerbs.Post)]
[AbpMvcAuthorize(AppPermissions.Pages_Master_Location_Delete)]
public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, LocationViewModel item)
{
try
{
if (item != null && item.Id.HasValue)
{
_locationManager.Delete(item.Id.Value);
}
}
catch (Exception ex)
{
ModelState.AddModelError("DeleteError", "error");
}
return Json(new[] { item }.ToDataSourceResult(request, ModelState));
}
Response is not json but Asp.net exception instead. Please advice how to resolve.
Server Error in '/' Application.
The DELETE statement conflicted with the REFERENCE constraint "FK_dbo.AppStockAmount_dbo.AppLocation_LocationId". The conflict occurred in database "Demo", table "dbo.AppStockAmount", column 'LocationId'. The statement has been terminated.
13 Answer(s)
-
0
Hi,
Do you use ASP.NET MVC 5.x version or ASP.NET Core version ?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I'm using ASP.NET MVC. I've tried to On/Off Custom Errors but always return Error Page when exception occurs.
Btw, same code has tested on classic MVC project and working. Not sure why error still pops after exception catched and processed. In this case I need to reture error message to client. After action executed, I also traced running into Application_Error in global.ascx.cs. Please help to verify, thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I've tried below configuration but still not working.
Configuration.Modules.AbpMvc().IsValidationEnabledForControllers = false;btw: My Abp version is 1.0
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
Have you tried without [DontWrapResult] attribute ? Can you also share a screenshot of your error page if it does not work ?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Yes,i tried but still not working.
The exception I got is as expected. I try to delete an record which has key constraint. The problem is I can't get a Json result with error message. Always asp.net yellow page html (error page) instead. The same code tested on default ASP.NET MVC project and working. Does any Abp function to intercept error and return error?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
Can you try to add this attribute to your action ?
[UnitOfWork(IsDisabled = true)]If that does not work, can you send your project to <a href="mailto:[email protected]">[email protected]</a>.
Thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Anyone can help on this?? I already catch the exception in action why still jump to Abp OnException process??
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
<cite>ismcagdas: </cite> Hi,
Can you try to add this attribute to your action ?
[UnitOfWork(IsDisabled = true)]If that does not work, can you send your project to <a href="mailto:[email protected]">[email protected]</a>.
Thanks.
It's working now. So I guess it's due to Post Commit of UOM after action done?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
Yes you are right, Since ABP Controller Actions are UOW by default, your operation is committed after your action's code is executed. Can you try to remove this attribute [UnitOfWork(IsDisabled = true)] and change your Action's return type to JsonResult instead of ActionResult ?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Just tried use JsonResult but not working. still got code 500 & yellow page.
So if I want to use UOM in controller i have to initialize UOM in action instead?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
No actually you shouldn't do that. This seems like a bug. I will try to find it and let you know of the result.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
If I enable UnitOfWork on Action, anyway to complete UOM in "Catch Exception"? So default UOM will not be trigger after Action done.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
No, because the code calls your controller action creates the UOW and it commits it. Can you send your project to <a href="mailto:[email protected]">[email protected]</a> ? Normally this should work as expected, I want to try it with your project ?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)