你可以这么处理,首先定义一个方法 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");
}
}
{
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");
}
}
你好 我是楼主
我想要在当前页面以某种方式显示错误信息,比如alert弹出框 你这样返回一个alert的页面还是进行了转向啊
//判断是否存在
$.get("Home/checkFileIsExist",null,function(data){
if(存在)
window.location.href='Home/download';
else
alert('下载失败');
})
});
response.write("<script>xxxx</script>");
response.end();
return null;
之前进行转向是因为缺少了unobtrusive-ajax脚本 并且要使用ajax请求