I have an ASP.NET web application, and I wanted to know how I could display an error message box when an exception is thrown.
For example,
If you are using .NET Core with MVC and Razor, you have several levels of preprocessing before your page is rendered. Then I suggest that you try wrapping a conditional error message at the top of your view page, like so:
In ViewController.cs:
if (file.Length < 800000)
{
ViewData["errors"] = "";
}
else
{
ViewData["errors"] = "File too big. (" + file.Length.ToString() + " bytes)";
}
In View.cshtml:
@if (ViewData["errors"].Equals(""))
{
@:Everything is fine.
}
else
{
@:
}