如何在MVC视图中处理@()标记内的错误;还有为什么DivideByZero错误?

时间:2014-06-26 20:59:29

标签: c# javascript asp.net-mvc

我不明白这个错误!我有一个JavaScript函数,我在运行时为字符串赋值,如下所示:

<script type="text/javascript">
    RefreshDashButtons() {
...

    Line 532:         dash10FTEs = "@(branch.FTEs.ToString())";
    Line 533:         dash10TurnoversOpen = @(branch.Turnovers.ToString()) + " | " + @(branch.OpenPositions.ToString());
    Line 534:         dash10Style = "@(branch.MTDDash10StyleOV)";
    Line 535:     }
    Line 536: }
...

    }
</script>

当执行到达第534行时,我得到DivideByZeroException。这是堆栈跟踪:

System.DivideByZeroException was unhandled by user code
  HResult=-2147352558
  Message=Attempted to divide by zero.
  Source=mscorlib
  StackTrace:
       at System.Decimal.FCallDivide(Decimal& d1, Decimal& d2)
       at System.Decimal.op_Division(Decimal d1, Decimal d2)
       at ASP._Page_Views_Home_Index_cshtml.Execute() in c:\Projects_VS2010\Dashboard\Views\Home\Index.cshtml:line 534
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.StartPage.RunPage()
       at System.Web.WebPages.StartPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
  InnerException: null

这显然是某种内部.NET错误,这不是我主要担心的问题(尽管很奇怪)。我想做的是优雅地处理错误,甚至只是吸收错误。任何人都可以建议如何使用JavaScript内部的.NET代码?我试过评论这条线;但是然后错误发生在前一行,这也只是分配一个字符串。

我已经完成了代码,一切都很好,直到我点击这一行。在运行时,branch.MTDDash10StyleOV =&#34; bbtext-normal&#34;。也就是说,从第533行开始。

希望这有帮助吗?

0 个答案:

没有答案