1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\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
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
15 using System.Diagnostics.CodeAnalysis;
\r
17 using System.Web.UI;
\r
19 [FileLevelControlBuilder(typeof(ViewPageControlBuilder))]
\r
20 public class ViewPage : Page, IViewDataContainer {
\r
22 private string _masterLocation;
\r
23 private ViewDataDictionary _viewData;
\r
25 public AjaxHelper Ajax {
\r
30 public HtmlHelper Html {
\r
35 public string MasterLocation {
\r
37 return _masterLocation ?? String.Empty;
\r
40 _masterLocation = value;
\r
44 public object Model {
\r
46 return ViewData.Model;
\r
50 public TempDataDictionary TempData {
\r
52 return ViewContext.TempData;
\r
56 public UrlHelper Url {
\r
61 public ViewContext ViewContext {
\r
66 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
\r
67 Justification = "This is the mechanism by which the ViewPage gets its ViewDataDictionary object.")]
\r
68 public ViewDataDictionary ViewData {
\r
70 if (_viewData == null) {
\r
71 SetViewData(new ViewDataDictionary());
\r
80 public HtmlTextWriter Writer {
\r
85 public virtual void InitHelpers() {
\r
86 Ajax = new AjaxHelper(ViewContext, this);
\r
87 Html = new HtmlHelper(ViewContext, this);
\r
88 Url = new UrlHelper(ViewContext.RequestContext);
\r
91 [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
\r
92 protected override void OnPreInit(EventArgs e) {
\r
95 if (!String.IsNullOrEmpty(MasterLocation)) {
\r
96 MasterPageFile = MasterLocation;
\r
100 protected override void Render(HtmlTextWriter writer) {
\r
103 base.Render(writer);
\r
110 public virtual void RenderView(ViewContext viewContext) {
\r
111 ViewContext = viewContext;
\r
113 // Tracing requires Page IDs to be unique.
\r
114 ID = Guid.NewGuid().ToString();
\r
115 ProcessRequest(HttpContext.Current);
\r
118 protected virtual void SetViewData(ViewDataDictionary viewData) {
\r
119 _viewData = viewData;
\r