-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMViewPage.cs
102 lines (95 loc) · 2.45 KB
/
MViewPage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Web.UI;
namespace Moon.Mvc
{
[FileLevelControlBuilder(typeof(ViewPageControlBuilder))]
public class MViewPage : Page
{
protected Type _ModelType;
protected object _Model
{
get;
set;
}
public virtual void SetModel(object model)
{
if (model != null)
{
_ModelType = model.GetType();
_Model = model;
}
}
public virtual T Model<T>()
{
if (_ModelType!=null&&_ModelType != typeof(T))
{
throw new Exception("Model的实际类型和你指定的类型不一致,Model实际类型为:" + _ModelType.FullName);
}
if (_Model == null)
{
return default(T);
}
return (T)_Model;
}
/// <summary>
/// Model's Type
/// </summary>
public Type ModelType
{
get
{
return _ModelType;
}
}
/// <summary>
/// html编码
/// </summary>
/// <param name="html">需要编码的html</param>
/// <returns></returns>
public string HtmlEncode(string html){
return System.Web.HttpUtility.HtmlEncode(html);
}
/// <summary>
/// html解码
/// </summary>
/// <param name="html">需要解码的html</param>
/// <returns></returns>
public string HtmlDecode(string html){
return System.Web.HttpUtility.HtmlDecode(html);
}
protected Dictionary<string, object> _ViewData = new Dictionary<string, object>();
/// <summary>
/// 视图数据字典
/// </summary>
public Dictionary<string, object> ViewData
{
get
{
return _ViewData;
}
set
{
_ViewData = value;
}
}
private string _RootUrl;
/// <summary>
/// 当前网站的根地址
/// </summary>
public string RootUrl
{
internal set
{
_RootUrl = value;
}
get
{
return _RootUrl;
}
}
}
}