【问题标题】:How to show catch exception message on view page?如何在视图页面上显示捕获异常消息?
【发布时间】:2014-02-14 08:06:32
【问题描述】:
catch(Exception ex)
{
   System.Diagnostic.StackTrace st=New System.Diagnostic.StackTrace(ex,true);
   System.Diagnostic.StackFrame sf=st.getframe(st.frame-1);
   int irow=sf.GetFileLineNumber();
   int icol=sf.GetFileColumnNumber();
   string smsg="Row: "+irow+ " Col "+icol;
   Throw New Exception(smsg, ex);
}

这是我在 main 方法中编写的代码,它是在 mvc3 razor 中将 excel 表的所有值插入数据库的实现。现在,请帮助我如何在查看页面上显示此异常消息?

【问题讨论】:

标签: c# asp.net-mvc asp.net-mvc-3 exception razor


【解决方案1】:

您始终可以在 ViewBag 中插入错误消息,然后将其显示在您之后显示的视图中。但也许您想要更高级的解决方案?

ViewBag.MyExeption = theobjectcontainingtheerrorinfoyouwanttosee

【讨论】:

  • 请记住,这段代码是用 main 方法编写的。我有一个单独的文件夹,其中包含此方法和一个由控制器调用的 .exe 文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 2011-11-06
  • 1970-01-01
  • 2015-10-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多