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 public abstract class ViewResultBase : ActionResult {
\r
18 private TempDataDictionary _tempData;
\r
19 private ViewDataDictionary _viewData;
\r
20 private ViewEngineCollection _viewEngineCollection;
\r
21 private string _viewName;
\r
23 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
\r
24 Justification = "This entire type is meant to be mutable.")]
\r
25 public TempDataDictionary TempData {
\r
27 if (_tempData == null) {
\r
28 _tempData = new TempDataDictionary();
\r
42 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
\r
43 Justification = "This entire type is meant to be mutable.")]
\r
44 public ViewDataDictionary ViewData {
\r
46 if (_viewData == null) {
\r
47 _viewData = new ViewDataDictionary();
\r
56 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
\r
57 Justification = "This entire type is meant to be mutable.")]
\r
58 public ViewEngineCollection ViewEngineCollection {
\r
60 return _viewEngineCollection ?? ViewEngines.Engines;
\r
63 _viewEngineCollection = value;
\r
67 public string ViewName {
\r
69 return _viewName ?? String.Empty;
\r
76 public override void ExecuteResult(ControllerContext context) {
\r
77 if (context == null) {
\r
78 throw new ArgumentNullException("context");
\r
80 if (String.IsNullOrEmpty(ViewName)) {
\r
81 ViewName = context.RouteData.GetRequiredString("action");
\r
84 ViewEngineResult result = null;
\r
87 result = FindView(context);
\r
91 ViewContext viewContext = new ViewContext(context, View, ViewData, TempData);
\r
92 View.Render(viewContext, context.HttpContext.Response.Output);
\r
94 if (result != null) {
\r
95 result.ViewEngine.ReleaseView(context, View);
\r
99 protected abstract ViewEngineResult FindView(ControllerContext context);
\r