Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
Error message not displaying in Main Content Page


Thanks

What I have tried:

https://imgur.com/HMwE70d

 public class ErrorController : Controller
    {
        public PartialViewResult Index(string message)
        {
            ViewBag.ErrorMessage = message;
            return PartialView("_Error");
        }
        
    }



protected void Application_Error(object sender, EventArgs e)
        {
            Exception exception = Server.GetLastError();
            if (exception != null)
            {
                HttpException httpException = null;
                if (exception is HttpException)
                {
                    httpException = exception as HttpException;
                }

                Response.Clear();
                Server.ClearError();
                Response.Redirect(String.Format("~/Error/Index/?message={0}", HttpUtility.UrlEncode(exception.Message)));
                //Response.Redirect(string.Format("~/Error/Index/?message={0}", "", HttpUtility.UrlEncode(exception.Message)));
            }
        }



<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <h3>@ViewBag.ErrorMessage</h3>
</body>
</html>
Posted
Comments
SeeSharp2 16-Jul-21 16:01pm    
Debug your code. You posted 2 methods and only set the ViewBag in one of them. We have no idea which of your code actually runs.
Richard Deeming 19-Jul-21 4:55am    
HttpException httpException = null;
if (exception is HttpException)
{
    httpException = exception as HttpException;
}

That's a very verbose way of writing:
HttpException httpException = exception as HttpException;

It's also pointless, since you never use the httpException variable in your code.

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