У меня есть метод ToString()
для частичных видов.
Мои данные:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.DependencyInjection;
using System.IO;
using System.Threading.Tasks;
public static class ViewExtensions
{
public static async Task<string> ToString(this PartialViewResult partialView, ActionContext actionContext)
{
using (var writer = new StringWriter())
{
var services = actionContext.HttpContext.RequestServices;
var executor = services.GetRequiredService<PartialViewResultExecutor>();
var view = executor.FindView(actionContext, partialView).View;
var viewContext = new ViewContext(actionContext, view, partialView.ViewData, partialView.TempData, writer, new HtmlHelperOptions());
await view.RenderAsync(viewContext);
return writer.ToString();
}
}
}
В ASP.NET Core 2.2 я получаю эту ошибку:
System.InvalidOperationException: Служба для типа «Microsoft.AspNetCore.Mvc.ViewFeatures.PartialViewResultExecutor» не зарегистрирована.в Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService (поставщик IServiceProvider, Тип serviceType) в Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService [T] * поставщик IServiceProvider *)