// 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.RazorPages.Infrastructure; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc.RazorPages { /// /// An that renders a Razor Page. /// public class PageResult : ActionResult { /// /// Gets or sets the Content-Type header for the response. /// public string ContentType { get; set; } /// /// Gets the page model. /// public object Model => ViewData?.Model; /// /// Gets or sets the to be executed. /// public PageBase Page { get; set; } /// /// Gets or sets the for the page to be executed. /// public ViewDataDictionary ViewData { get; set; } /// /// Gets or sets the HTTP status code. /// public int? StatusCode { get; set; } /// public override Task ExecuteResultAsync(ActionContext context) { if (!(context is PageContext pageContext)) { throw new ArgumentException(Resources.FormatPageViewResult_ContextIsInvalid( nameof(context), nameof(Page), nameof(PageResult))); } var executor = context.HttpContext.RequestServices.GetRequiredService(); return executor.ExecuteAsync(pageContext, this); } } }