gpt4 book ai didi

c# - 如何在查看页面上显示捕获异常消息?

转载 作者:行者123 更新时间:2023-12-02 04:36:58 25 4
gpt4 key购买 nike

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);
}

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

最佳答案

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

ViewBag.MyExeption = theobjectcontainingtheerrorinfoyouwanttosee

关于c# - 如何在查看页面上显示捕获异常消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21773881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com