zoukankan      html  css  js  c++  java
  • mvc中的ViewData用到webfrom中去

     public class UserControlPageHelper : UserControl
        {
            protected IDictionary<string, object> ViewData
            {
                get
                {
                    return
                        (Dictionary<string, object>)
                        (Session["ViewData"] ?? (Session["ViewData"] = new Dictionary<string, object>()));
                }
            }
            protected override void OnUnload(EventArgs e)
            {
                base.OnUnload(e);
                if (Session["ViewData"] == null) return;
                Session.Remove("ViewData");
                GC.Collect();
            }
    
            protected dynamic Model
            {
                get { return ViewData["Model"]; }
                set { ViewData["Model"] = value; }
            }
      }
    }

          分别继承MasterPage, Page 和 UserController 类
          注意一点 判断 ViewData.ContainsKey("x")

          用法:(前台代码)

     <% if (ViewData.ContainsKey("__tip"))
           {
               string tip = (string)ViewData["__tip"];
               if (!string.IsNullOrEmpty(tip))
               {
                   Response.Write(tip);
               }
           }
           if (ViewData.ContainsKey("__refresh"))
           {
               string refresh = (string)ViewData["__refresh"];
               if (!string.IsNullOrEmpty(refresh))
               {
                   Response.Write(refresh);
               } 
           }
           
        %>
  • 相关阅读:
    T4设计时模板调试
    MVC开发T4代码生成之一文本模板基础
    经典选项卡
    IE 调试工具 Utilu IE Collection:IE5.5、6.0、7.0, 8.0…各版本浏览器兼容性测试工具
    滚动读行!
    自定义标签的用法、支持IE6
    jQuery 参数传递例子
    IMG在IE6下不能HOVER的解决办法!
    点击渐变弹出层
    操作滚动条滚动到指定位置
  • 原文地址:https://www.cnblogs.com/zengxiangzhan/p/2410831.html
Copyright © 2011-2022 走看看