Merge pull request #485 from mtausig/master
[mono.git] / mcs / class / System.Web.Mvc3 / Mvc / WebViewPage`1.cs
1 namespace System.Web.Mvc {
2     using System.Diagnostics.CodeAnalysis;
3
4     public abstract class WebViewPage<TModel> : WebViewPage {
5         private ViewDataDictionary<TModel> _viewData;
6
7         public new AjaxHelper<TModel> Ajax {
8             get;
9             set;
10         }
11
12         public new HtmlHelper<TModel> Html {
13             get;
14             set;
15         }
16
17         public new TModel Model {
18             get {
19                 return ViewData.Model;
20             }
21         }
22
23         [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This is the mechanism by which the ViewPage gets its ViewDataDictionary object.")]
24         public new ViewDataDictionary<TModel> ViewData {
25             get {
26                 if (_viewData == null) {
27                     SetViewData(new ViewDataDictionary<TModel>());
28                 }
29                 return _viewData;
30             }
31             set {
32                 SetViewData(value);
33             }
34         }
35
36         public override void InitHelpers() {
37             base.InitHelpers();
38
39             Ajax = new AjaxHelper<TModel>(ViewContext, this);
40             Html = new HtmlHelper<TModel>(ViewContext, this);
41         }
42
43         protected override void SetViewData(ViewDataDictionary viewData) {
44             _viewData = new ViewDataDictionary<TModel>(viewData);
45
46             base.SetViewData(_viewData);
47         }
48     }
49 }