我来自带有桌面应用程序的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? } }
注意:我故意在那里放两个@来强制异常,所以我可以看到如何显示异常消息.
解决方法
@H_404_9@ 当您使用< p>标签,剃刀引擎退出c#模式并进入html模式.尝试<p>@exception.Message;</p>
在拦截区.