简体   繁体   中英

How to show catch exception message on view page?

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

This is the code I have written in my main method which is implementation of insert all values of excel sheet into database in mvc3 razor. Now, Please help me how will I show this exception message on view page?

You can always insert the error message in the ViewBag and then show it in the view you display after. But maybe you want a more advanced solution?

ViewBag.MyExeption = theobjectcontainingtheerrorinfoyouwanttosee

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM