// 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.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Mvc
{
///
/// An which renders a view component to the response.
///
public class ViewComponentResult : ActionResult
{
///
/// Gets or sets the arguments provided to the view component.
///
public object Arguments { get; set; }
///
/// Gets or sets the HTTP status code.
///
public int? StatusCode { get; set; }
///
/// Gets or sets the name of the view component to invoke. Will be ignored if
/// is set to a non-null value.
///
public string ViewComponentName { get; set; }
///
/// Gets or sets the type of the view component to invoke.
///
public Type ViewComponentType { get; set; }
///
/// Get 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 Task ExecuteResultAsync(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var services = context.HttpContext.RequestServices;
var executor = services.GetRequiredService();
return executor.ExecuteAsync(context, this);
}
}
}