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.Globalization;
\r
17 using System.Web.Mvc.Resources;
\r
19 public class WebFormView : IView {
\r
21 private IBuildManager _buildManager;
\r
23 public WebFormView(string viewPath)
\r
24 : this(viewPath, null) {
\r
27 public WebFormView(string viewPath, string masterPath) {
\r
28 if (String.IsNullOrEmpty(viewPath)) {
\r
29 throw new ArgumentException(MvcResources.Common_NullOrEmpty, "viewPath");
\r
32 ViewPath = viewPath;
\r
33 MasterPath = masterPath ?? String.Empty;
\r
36 internal IBuildManager BuildManager {
\r
38 if (_buildManager == null) {
\r
39 _buildManager = new BuildManagerWrapper();
\r
41 return _buildManager;
\r
44 _buildManager = value;
\r
48 public string MasterPath {
\r
53 public string ViewPath {
\r
58 public virtual void Render(ViewContext viewContext, TextWriter writer) {
\r
59 if (viewContext == null) {
\r
60 throw new ArgumentNullException("viewContext");
\r
63 object viewInstance = BuildManager.CreateInstanceFromVirtualPath(ViewPath, typeof(object));
\r
64 if (viewInstance == null) {
\r
65 throw new InvalidOperationException(
\r
67 CultureInfo.CurrentUICulture,
\r
68 MvcResources.WebFormViewEngine_ViewCouldNotBeCreated,
\r
72 ViewPage viewPage = viewInstance as ViewPage;
\r
73 if (viewPage != null) {
\r
74 RenderViewPage(viewContext, viewPage);
\r
78 ViewUserControl viewUserControl = viewInstance as ViewUserControl;
\r
79 if (viewUserControl != null) {
\r
80 RenderViewUserControl(viewContext, viewUserControl);
\r
84 throw new InvalidOperationException(
\r
86 CultureInfo.CurrentUICulture,
\r
87 MvcResources.WebFormViewEngine_WrongViewBase,
\r
91 private void RenderViewPage(ViewContext context, ViewPage page) {
\r
92 if (!String.IsNullOrEmpty(MasterPath)) {
\r
93 page.MasterLocation = MasterPath;
\r
96 page.ViewData = context.ViewData;
\r
97 page.RenderView(context);
\r
100 private void RenderViewUserControl(ViewContext context, ViewUserControl control) {
\r
101 if (!String.IsNullOrEmpty(MasterPath)) {
\r
102 throw new InvalidOperationException(MvcResources.WebFormViewEngine_UserControlCannotHaveMaster);
\r
105 control.ViewData = context.ViewData;
\r
106 control.RenderView(context);
\r