Click here to Skip to main content
14,931,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to show exception that occurred in on the same view in mvc on click of sumit button of view..

i have a exception filter in App_Start that register in application start event
but when exception occurred it show the same error page always

i have used below code..

What I have tried:

if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
{
filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
exception.exception = filterContext.Exception;
exception.CustomData = filterContext.Exception.Message; //"Error Message";
ExceptionPublisher.clsExceptionHandler.Publish(exception);
filterContext.Result = new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = new
{
filterContext.Exception.Message,


}
};


filterContext.ExceptionHandled = true;

}
else if (filterContext.Exception != null)
{
exception.exception = filterContext.Exception;
exception.CustomData = filterContext.Exception.Message; //"Error Message";
ExceptionPublisher.clsExceptionHandler.Publish(exception);
//


string actionName = filterContext.RouteData.Values["action"].ToString();
Type controllerType = filterContext.Controller.GetType();
string controllerName = filterContext.RouteData.Values["controller"].ToString();
// var method = controllerType.GetMethod(actionName);
// var returnType = method.ReturnType;

//


if (HttpContext.Current.Session["LoginUser"] != null)
{
filterContext.HttpContext.Response.Redirect(@"/Home/Error", true);
}
else
{


filterContext.HttpContext.Response.Redirect(@"/Account/Login", true);
}
}

else
{
base.OnException(filterContext);
}
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900