title: ASP.NET CORE Render Razor View to string with controller parameters
body: <p>I need to render a partial view as string.
  For this I use following Helper class:</p>
  <pre><code>public static string RenderRazorViewToString(Controller controller, string viewName, object model = null)
  {
      controller.ViewData.Model = model;
      using (var sw = new StringWriter())
      {
          IViewEngine viewEngine =
              controller.HttpContext.RequestServices.GetService(typeof(ICompositeViewEngine)) as
                  ICompositeViewEngine;
          ViewEngineResult viewResult = viewEngine.FindView(controller.ControllerContext, viewName, false);
  
          ViewContext viewContext = new ViewContext(
              controller.ControllerContext,
              viewResult.View,
              controller.ViewData,
              controller.TempData,
              sw,
              new HtmlHelperOptions()
          );
          viewResult.View.RenderAsync(viewContext);
          return sw.GetStringBuilder().ToString();
      }
  }
  </code></pre>
  <p>This works but I now need a similiar Method that also accepts a list of parameters.
  The View I want to render as a string is called by following Controller method:</p>
  <pre><code>public Task&lt;IActionResult&gt; IndexPartial(string? searchValue, string? filterValue)
  {
     IQueryable&lt;Invoice&gt; query
     ....Manipulate query by searchValue and filterValue
     return PartialView(&quot;IndexPartial&quot;,await query.ToListAsync());
  }
  </code></pre>
  <p>When I call <code>Helper.RenderRazorViewToString(controller, &quot;IndexPartial&quot;, model)</code> I have to pass the stringValue and FilterValue.</p>
  <p>Does Anybody know how to achieve this?</p>