I have one Action controller that has a completely different view than the rest of my application, and I want all exceptions thrown by this action to display a different error page than the rest of my application.
I changed the HandleError attribute, but it does NOT load the error page at all when an exception occurs.
[HttpPost]
[HandleError(View = "UPI_Error")]
public ActionResult ParticipantUpdate1(Participant part)
{
try
{
mps.ParticipantUpdate(LogonTicket, ParticipantID, part);
}
catch(Exception ex)
{
string x = ex.Message;
}
return View();
}
Any ideas?
UPDATE
OK, changed to this:
[HttpPost]
[HandleError(View = "UPI_Error", ExceptionType = typeof(ArgumentException))]
public ActionResult ParticipantUpdateSuccess(Participant part)
{
Participant OrigPart = CopyParticipant(part);
try
{
string result = mps.ParticipantUpdate(LogonTicket, ParticipantID, OrigPart);
if (result != "Update Success")
{
throw new ArgumentException(result);
}
}
catch (Exception e)
{
throw new ArgumentException(e.Message);
}
return View();
}
But this STILL does not load the UPI_Error page. Calling "Member" returns this exception:
System.ServiceModel.FaultException`1 was unhandled by user code
HResult=-2146233087
Message=ORA-12899: value too large for column "CLI"."CLI_MAIN_ZIP" (actual: 21, maximum: 11)
The article follows this link: http://www.c-sharpcorner.com/UploadFile/ff2f08/exception-or-error-handling-in-Asp-Net-mvc-using-handleerror/
, HandleError , . - , ?
, -, - YSOD .
UPDATE
, . , TempData, . - . NULL-. ?
[HttpPost]
[HandleError(View = "UPI_Error")]
public ActionResult ParticipantUpdateSuccess(Participant part)
{
bool error = false;
Participant OrigPart = CopyParticipant(part);
try
{
string result = mps.ParticipantUpdate(LogonTicket, ParticipantID, OrigPart);
if (result != "Update Success")
{
throw new ArgumentException(result);
}
}
catch (Exception ex)
{
error = true;
TempData["exception"] = ex;
}
if (!error)
{
return View();
}
else
{
return RedirectToAction("UPIError");
}
}
public ActionResult UPIError()
{
ViewBag.Exception = TempData["exception"];
return View();
}
:
= . : ASP._Page_Views_Home_UPIError_cshtml.Execute() ... \Views\Home\UPIError.cshtml: 4
4 (, ):
Layout = "~/Views/Shared/_UPILayout.cshtml";
, . Null Reference, .