-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
PartialViewResult.cs
76 lines (63 loc) · 2.61 KB
/
PartialViewResult.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable enable
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;
/// <summary>
/// Represents an <see cref="ActionResult"/> that renders a partial view to the response.
/// </summary>
public class PartialViewResult : ActionResult, IStatusCodeActionResult
{
/// <summary>
/// Gets or sets the HTTP status code.
/// </summary>
public int? StatusCode { get; set; }
/// <summary>
/// Gets or sets the name or path of the partial view that is rendered to the response.
/// </summary>
/// <remarks>
/// When <c>null</c>, defaults to <see cref="ControllerActionDescriptor.ActionName"/>.
/// </remarks>
public string? ViewName { get; set; }
/// <summary>
/// Gets the view data model.
/// </summary>
public object? Model => ViewData?.Model;
/// <summary>
/// Gets or sets the <see cref="ViewDataDictionary"/> used for rendering the view for this result.
/// </summary>
public ViewDataDictionary ViewData { get; set; } = default!;
/// <summary>
/// Gets or sets the <see cref="ITempDataDictionary"/> used for rendering the view for this result.
/// </summary>
public ITempDataDictionary TempData { get; set; } = default!;
/// <summary>
/// Gets or sets the <see cref="IViewEngine"/> used to locate views.
/// </summary>
/// <remarks>When <c>null</c>, an instance of <see cref="ICompositeViewEngine"/> from
/// <c>ActionContext.HttpContext.RequestServices</c> is used.</remarks>
public IViewEngine? ViewEngine { get; set; }
/// <summary>
/// Gets or sets the Content-Type header for the response.
/// </summary>
public string? ContentType { get; set; }
/// <inheritdoc />
public override Task ExecuteResultAsync(ActionContext context)
{
ArgumentNullException.ThrowIfNull(context);
var services = context.HttpContext.RequestServices;
var executor = services.GetService<IActionResultExecutor<PartialViewResult>>();
if (executor == null)
{
throw new InvalidOperationException(Mvc.Core.Resources.FormatUnableToFindServices(
nameof(IServiceCollection),
"AddControllersWithViews()",
"ConfigureServices(...)"));
}
return executor.ExecuteAsync(context, this);
}
}