【问题标题】:jQuery mobile and mvc4, how to redirect to a custom error page replacing "Error Loading Page" messagejQuery mobile 和 mvc4,如何重定向到自定义错误页面替换“错误加载页面”消息
【发布时间】:2012-11-15 10:24:44
【问题描述】:

当发生未处理的异常时,我正在尝试设置自定义错误页面(Views/Shared 文件夹中的 Error.vbhtml)。我看到的只是黄色背景上的“加载页面错误”消息。

这些是我迄今为止为实现结果所做的工作:

  1. 我已在 web.config 中将 customErrors 模式设置为“开启”
  2. 检查 FilterConfig.vb 中是否存在 filters.Add(New HandleErrorAttribute())
  3. 抛出异常,使用firebug的Net选项卡查看出错的页面,可以看到HTML选项卡有Error.vbhtml中的自定义消息。

我假设由于 jQuery mobile 依赖 ajax 进行页面导航,因此错误页面由于某种原因没有显示。如何显示该页面?有什么想法吗?

感谢您的帮助。

【问题讨论】:

    标签: jquery-mobile asp.net-mvc-4


    【解决方案1】:

    通过在 _Layout.vbhtml 中添加以下 javascript 代码解决了这个问题

         <script type="text/javascript">
              $(document).live("pagechangefailed", function (e, data) {
                //alert("pagechangefailed live");
                var url = '@Url.Action("CustomError", "Account")';
                window.location.href = url;  
    
              }); 
            </script>
    

    其中 CustomError 是 AccountController 中新创建的操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      相关资源
      最近更新 更多