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"__tip"stringstring"__tip"ifstringif"__refresh"stringstring"__refresh"ifstring
%>
本文转自曾祥展博客园博客,原文链接:http://www.cnblogs.com/zengxiangzhan/archive/2012/03/21/2410831.html,如需转载请自行联系原作者