How to display an error message box in a web application asp.net c#

后端 未结 7 1367
小蘑菇
小蘑菇 2020-12-03 18:28

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,

                 


        
7条回答
  •  时光取名叫无心
    2020-12-03 18:50

    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 { @: }

提交回复
热议问题