文章内容

2018/1/7 10:44:22,作 者: 黄兵

asp.net mvc跳转提示实现

在执行完操作后往往需要显示执行的结果,可以使用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>

跳转数据

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5.   
  6. namespace EditorOnline.Util  
  7. {  
  8.     public class RedirectData  
  9.     {  
  10.         public static Dictionary<String, Object> GetSuccess(String url, String message)  
  11.         {  
  12.             return GetRedirect(url, message, 2);  
  13.         }  
  14.   
  15.         public static Dictionary<String, Object> GetRedirect(String url, String message, int time)  
  16.         {  
  17.             Dictionary<String, Object> dic = new Dictionary<stringobject>();  
  18.             dic.Add("url", url);  
  19.             dic.Add("message", message);  
  20.             dic.Add("time", time);  
  21.             return dic;  
  22.         }  
  23.   
  24.         public static Dictionary<String, Object> GetFail(String url, String message)  
  25.         {  
  26.             return GetRedirect(url, message, 3);  
  27.         }  
  28.   
  29.     }  
  30. }  

跳转功能

  1. /// <summary>  
  2.         /// 页面跳转视图  
  3.         /// </summary>  
  4.         /// <param name="url"></param>  
  5.         /// <param name="message"></param>  
  6.         /// <param name="time"></param>  
  7.         /// <returns></returns>  
  8.         protected ViewResult Redirect(String url, String message, int time)  
  9.         {  
  10.             this.ViewBag.Redirect = RedirectData.GetRedirect(url, message, time);  
  11.             return this.View("redirect");  
  12.         }  

调用示例

  1. return Redirect("/Home/Index""执行成功", 2);  

在需要跳转的控制器中使用


本文转载自:asp.net mvc跳转提示实现

分享到:

发表评论

评论列表