开发者

How to display Exception Message (Razor/C#)

开发者 https://www.devze.com 2023-03-08 03:50 出处:网络
I come from a C# background with Desktop apps and mostly PHP for web stuff, and I thought that with Razor code you could do something like this to display an exception message (just like you can in de

I come from a C# background with Desktop apps and mostly PHP for web stuff, and I thought that with Razor code you could do something like this to display an exception message (just like you can in desktop apps):

@{
    // Other code....



    try
    {
         WebMail.Send(to: "talk@@blah.com",  
        subject: "New message from - " + email, 
        body: message 
        ); 

        <p>Thanks for your message. We'll be in touch shortly!</p>
    }
    catch(Exception exception)
    {
          <p>开发者_运维知识库exception.Message;</p> // Why doesn't this display exception details?
    }
}

Note: I have intentionally put two @'s in there to force an exception, so I can see how to display exception messages.


When you use the <p> tag, the razor engine drops out of c# mode and into html mode. Try

<p>@exception.Message;</p>

in the catch block.

0

精彩评论

暂无评论...
验证码 换一张
取 消