// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ViewEngines; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc { /// /// Represents an that renders a view to the response. /// public class ViewResult : ActionResult { /// /// Gets or sets the HTTP status code. /// public int? StatusCode { get; set; } /// /// Gets or sets the name or path of the view that is rendered to the response. /// /// /// When null, defaults to . /// public string ViewName { get; set; } /// /// Gets the view data model. /// public object Model => ViewData?.Model; /// /// Gets or sets the for this result. /// public ViewDataDictionary ViewData { get; set; } /// /// Gets or sets the for this result. /// public ITempDataDictionary TempData { get; set; } /// /// Gets or sets the used to locate views. /// /// When null, an instance of from /// ActionContext.HttpContext.RequestServices is used. public IViewEngine ViewEngine { get; set; } /// /// Gets or sets the Content-Type header for the response. /// public string ContentType { get; set; } /// public override async Task ExecuteResultAsync(ActionContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var executor = context.HttpContext.RequestServices.GetRequiredService>(); await executor.ExecuteAsync(context, this); } } }