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
18 public abstract class ViewResultBase : ActionResult {
\r
19 private TempDataDictionary _tempData;
\r
20 private ViewDataDictionary _viewData;
\r
21 private ViewEngineCollection _viewEngineCollection;
\r
22 private string _viewName;
\r
24 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
\r
25 Justification = "This entire type is meant to be mutable.")]
\r
26 public TempDataDictionary TempData {
\r
28 if (_tempData == null) {
\r
29 _tempData = new TempDataDictionary();
\r
43 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
\r
44 Justification = "This entire type is meant to be mutable.")]
\r
45 public ViewDataDictionary ViewData {
\r
47 if (_viewData == null) {
\r
48 _viewData = new ViewDataDictionary();
\r
57 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
\r
58 Justification = "This entire type is meant to be mutable.")]
\r
59 public ViewEngineCollection ViewEngineCollection {
\r
61 return _viewEngineCollection ?? ViewEngines.Engines;
\r
64 _viewEngineCollection = value;
\r
68 public string ViewName {
\r
70 return _viewName ?? String.Empty;
\r
77 public override void ExecuteResult(ControllerContext context) {
\r
78 if (context == null) {
\r
79 throw new ArgumentNullException("context");
\r
81 if (String.IsNullOrEmpty(ViewName)) {
\r
82 ViewName = context.RouteData.GetRequiredString("action");
\r
85 ViewEngineResult result = null;
\r
88 result = FindView(context);
\r
92 TextWriter writer = context.HttpContext.Response.Output;
\r
93 ViewContext viewContext = new ViewContext(context, View, ViewData, TempData, writer);
\r
94 View.Render(viewContext, writer);
\r
96 if (result != null) {
\r
97 result.ViewEngine.ReleaseView(context, View);
\r
101 protected abstract ViewEngineResult FindView(ControllerContext context);
\r