C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Global Exception Handling for MVC controller
WhatsApp
Aravindhan Dhandapani
Jul 27
2015
973
0
0
using
System.Web.Mvc;
public
abstract
partial
class
BaseController : Controller
{
protected
override
void
OnException(ExceptionContext context)
{
base
.OnException(context);
string
controller = context.RouteData.Values[
"controller"
].ToString();
string
action = context.RouteData.Values[
"action"
].ToString();
if
(context.Exception !=
null
)
{
HandleErrorInfo errorModel =
new
HandleErrorInfo(context,controller,action);
if
(Request.IsAjaxRequest())
{
context.Result = View();
}
}
context.ExceptionHandled =
true
;
}
}
Global Exception Handling
MVC
controller
Up Next
Global Exception Handling for MVC controller