1
/* ****************************************************************************
3 * Copyright (c) Microsoft Corporation. All rights reserved.
5 * This software is subject to the Microsoft Public License (Ms-PL).
6 * A copy of the license can be found in the license.htm file included
7 * in this distribution.
9 * You must not remove this notice, or any other, from this software.
11 * ***************************************************************************/
13 namespace System
.Web
.Mvc
{
15 using System
.Globalization
;
17 using System
.Web
.Mvc
.Resources
;
19 public class WebFormView
: IView
{
21 private IBuildManager _buildManager
;
23 public WebFormView(string viewPath
)
24 : this(viewPath
, null) {
27 public WebFormView(string viewPath
, string masterPath
) {
28 if (String
.IsNullOrEmpty(viewPath
)) {
29 throw new ArgumentException(MvcResources
.Common_NullOrEmpty
, "viewPath");
33 MasterPath
= masterPath
?? String
.Empty
;
36 internal IBuildManager BuildManager
{
38 if (_buildManager
== null) {
39 _buildManager
= new BuildManagerWrapper();
44 _buildManager
= value;
48 public string MasterPath
{
53 public string ViewPath
{
58 public virtual void Render(ViewContext viewContext
, TextWriter writer
) {
59 if (viewContext
== null) {
60 throw new ArgumentNullException("viewContext");
63 object viewInstance
= BuildManager
.CreateInstanceFromVirtualPath(ViewPath
, typeof(object));
64 if (viewInstance
== null) {
65 throw new InvalidOperationException(
67 CultureInfo
.CurrentUICulture
,
68 MvcResources
.WebFormViewEngine_ViewCouldNotBeCreated
,
72 ViewPage viewPage
= viewInstance
as ViewPage
;
73 if (viewPage
!= null) {
74 RenderViewPage(viewContext
, viewPage
);
78 ViewUserControl viewUserControl
= viewInstance
as ViewUserControl
;
79 if (viewUserControl
!= null) {
80 RenderViewUserControl(viewContext
, viewUserControl
);
84 throw new InvalidOperationException(
86 CultureInfo
.CurrentUICulture
,
87 MvcResources
.WebFormViewEngine_WrongViewBase
,
91 private void RenderViewPage(ViewContext context
, ViewPage page
) {
92 if (!String
.IsNullOrEmpty(MasterPath
)) {
93 page
.MasterLocation
= MasterPath
;
96 page
.ViewData
= context
.ViewData
;
97 page
.RenderView(context
);
100 private void RenderViewUserControl(ViewContext context
, ViewUserControl control
) {
101 if (!String
.IsNullOrEmpty(MasterPath
)) {
102 throw new InvalidOperationException(MvcResources
.WebFormViewEngine_UserControlCannotHaveMaster
);
105 control
.ViewData
= context
.ViewData
;
106 control
.RenderView(context
);