// 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.ViewEngines; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc { /// /// Represents an that renders a partial view to the response. /// public class PartialViewResult : ActionResult { /// /// Gets or sets the HTTP status code. /// public int? StatusCode { get; set; } /// /// Gets or sets the name of the partial view to render. /// /// /// When null, defaults to . /// public string ViewName { get; set; } /// /// Gets the view data model. /// public object Model => ViewData?.Model; /// /// Gets or sets the used for rendering the view for this result. /// public ViewDataDictionary ViewData { get; set; } /// /// Gets or sets the used for rendering the view 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 services = context.HttpContext.RequestServices; var executor = services.GetRequiredService(); var result = executor.FindView(context, this); result.EnsureSuccessful(originalLocations: null); var view = result.View; using (view as IDisposable) { await executor.ExecuteAsync(context, view, this); } } } }