你可以这么处理,首先定义一个方法 public string AlertHtml(string content)
        {
            string html = string.Empty;
            html += @"<!DOCTYPE HTML>
                        <html>
                        <head>
                        <meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">
                        <title>提示</title>";
            html += string.Format(@"<script>
                        window.alert(""{0}"");
                            </script>", content);
            html += @"</head>
                            <body>
                            </body>
                    </html>";
            return html;
        }然后,调用[HttpGet]
        public ActionResult GetEventPass(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                    throw new Exception("下载地址不正确!");
                /*开始下载*/
                return new FileContentResult(eventPass.GetEventPassRequest(t_pass.SerialNumber), "application/vnd.apple.pkpass");            }
            catch (Exception ex)
            {
                return Content(AlertHtml("这张票已被注册了,请核查!"), "text/html");
            }
        }

解决方案 »

  1.   

    回复1楼:
    你好 我是楼主 
    我想要在当前页面以某种方式显示错误信息,比如alert弹出框 你这样返回一个alert的页面还是进行了转向啊
      

  2.   

    你应该在点击下载的时候,先去服务器查询是否下载的文件存在,如果存在再去指向下载文件的control$("#download").click(function(){
         //判断是否存在
         $.get("Home/checkFileIsExist",null,function(data){
             if(存在)
                 window.location.href='Home/download';
             else
                  alert('下载失败');
         })
    });
      

  3.   

    如果要弹出提示框 和webform一样啊
    response.write("<script>xxxx</script>");
    response.end();
    return null;
      

  4.   

    终于知道怎么使用mvc的javascriptResult返回js了
    之前进行转向是因为缺少了unobtrusive-ajax脚本 并且要使用ajax请求