This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
/
PageResult.cs
57 lines (49 loc) · 1.88 KB
/
PageResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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
{
/// <summary>
/// An <see cref="ActionResult"/> that renders a Razor Page.
/// </summary>
public class PageResult : ActionResult
{
/// <summary>
/// Gets or sets the Content-Type header for the response.
/// </summary>
public string ContentType { get; set; }
/// <summary>
/// Gets the page model.
/// </summary>
public object Model => ViewData?.Model;
/// <summary>
/// Gets or sets the <see cref="PageBase"/> to be executed.
/// </summary>
public PageBase Page { get; set; }
/// <summary>
/// Gets or sets the <see cref="ViewDataDictionary"/> for the page to be executed.
/// </summary>
public ViewDataDictionary ViewData { get; set; }
/// <summary>
/// Gets or sets the HTTP status code.
/// </summary>
public int? StatusCode { get; set; }
/// <inheritdoc />
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<PageResultExecutor>();
return executor.ExecuteAsync(pageContext, this);
}
}
}