您的位置:首页 > 编程语言 > ASP

asp.net mvc跳转提示实现

2015-02-12 11:18 603 查看
在执行完操作后往往需要显示执行的结果,可以使用js来实现执行后跳转并显示信息的功能。

视图

@{
Layout = null;
}

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>跳转提示</title>
</head>
<body>
<div class="system-message">
<h1>@ViewBag.Redirect["message"]</h1>
<p class="jump">
页面自动 <a id="href" href="@ViewBag.Redirect["url"]">跳转</a> 等待时间: <b id="wait">@ViewBag.Redirect["time"]</b>
</p>
</div>
<script type="text/javascript">
(function () {
var wait = document.getElementById('wait'), href = document.getElementById('href').href;
var interval = setInterval(function () {
var time = --wait.innerHTML;
if (time <= 0) {
location.href = href;
clearInterval(interval);
};
}, 1000);
})();
</script>
</body>
</html>

跳转数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EditorOnline.Util
{
public class RedirectData
{
public static Dictionary<String, Object> GetSuccess(String url, String message)
{
return GetRedirect(url, message, 2);
}

public static Dictionary<String, Object> GetRedirect(String url, String message, int time)
{
Dictionary<String, Object> dic = new Dictionary<string, object>();
dic.Add("url", url);
dic.Add("message", message);
dic.Add("time", time);
return dic;
}

public static Dictionary<String, Object> GetFail(String url, String message)
{
return GetRedirect(url, message, 3);
}

}
}

跳转功能
/// <summary>
/// 页面跳转视图
/// </summary>
/// <param name="url"></param>
/// <param name="message"></param>
/// <param name="time"></param>
/// <returns></returns>
protected ViewResult Redirect(String url, String message, int time)
{
this.ViewBag.Redirect = RedirectData.GetRedirect(url, message, time);
return this.View("redirect");
}调用示例
return Redirect("/Home/Index", "执行成功", 2);在需要跳转的控制器中使用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  .net js跳转 执行提示