【问题标题】:How to display Exception Message (Razor/C#)如何显示异常消息 (Razor/C#)
【发布时间】:2011-09-01 22:29:02
【问题描述】:

我来自 C# 背景,使用桌面应用程序,主要是用于 Web 的 PHP,我认为使用 Razor 代码可以执行类似的操作来显示异常消息(就像在桌面应用程序中一样):

@{
    // 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?
    }
}

注意:我故意放了两个@来强制异常,所以我可以看到如何显示异常消息。

【问题讨论】:

标签: c# .net exception razor webmatrix


【解决方案1】:

当您使用&lt;p&gt; 标记时,剃刀引擎会退出 c# 模式并进入 html 模式。试试

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

在 catch 块中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 2014-04-16
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    相关资源
    最近更新 更多