Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System.Web.Mvc / System.Web.Mvc / ViewUserControl`1.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System.Diagnostics.CodeAnalysis;\r
15 \r
16     public class ViewUserControl<TModel> : ViewUserControl where TModel : class {\r
17         private AjaxHelper<TModel> _ajaxHelper;\r
18         private HtmlHelper<TModel> _htmlHelper;\r
19         private ViewDataDictionary<TModel> _viewData;\r
20 \r
21         public new AjaxHelper<TModel> Ajax {\r
22             get {\r
23                 if (_ajaxHelper == null) {\r
24                     _ajaxHelper = new AjaxHelper<TModel>(ViewContext, this);\r
25                 }\r
26                 return _ajaxHelper;\r
27             }\r
28         }\r
29 \r
30         public new HtmlHelper<TModel> Html {\r
31             get {\r
32                 if (_htmlHelper == null) {\r
33                     _htmlHelper = new HtmlHelper<TModel>(ViewContext, this);\r
34                 }\r
35                 return _htmlHelper;\r
36             }\r
37         }\r
38 \r
39         public new TModel Model {\r
40             get {\r
41                 return ViewData.Model;\r
42             }            \r
43         }\r
44 \r
45         [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]\r
46         public new ViewDataDictionary<TModel> ViewData {\r
47             get {\r
48                 EnsureViewData();\r
49                 return _viewData;\r
50             }\r
51             set {\r
52                 SetViewData(value);\r
53             }\r
54         }\r
55 \r
56         protected override void SetViewData(ViewDataDictionary viewData) {\r
57             _viewData = new ViewDataDictionary<TModel>(viewData);\r
58 \r
59             base.SetViewData(_viewData);\r
60         }\r
61     }\r
62 }\r