title: Return View as String in .NET Core
body: <p>I found some article how to return view to string in ASP.NET, but could not covert any to be able to run it with .NET Core</p>
  
  <pre><code>public static string RenderViewToString(this Controller controller, string viewName, object model)
  {
      var context = controller.ControllerContext;
      if (string.IsNullOrEmpty(viewName))
          viewName = context.RouteData.GetRequiredString("action");
  
      var viewData = new ViewDataDictionary(model);
  
      using (var sw = new StringWriter())
      {
          var viewResult = ViewEngines.Engines.FindPartialView(context, viewName);
          var viewContext = new ViewContext(context, viewResult.View, viewData, new TempDataDictionary(), sw);
          viewResult.View.Render(viewContext, sw);
  
          return sw.GetStringBuilder().ToString();
      }
  }
  </code></pre>
  
  <p>which assumed to be able to call from a Controller using:</p>
  
  <pre><code>var strView = this.RenderViewToString("YourViewName", yourModel);
  </code></pre>
  
  <p>When I try to run the above into .NET Core I get lots of compilation errors.</p>
  
  <p>I tried to convert it to work with .NET Core, but failed, can anyone help with mentioning the required <code>using ..</code> and the required <code>"dependencies": {
      "Microsoft.AspNetCore.Mvc": "1.1.0",
  ...
    },</code> to be used in the <code>project.json</code>.</p>
  
  <p>some other sample codes are <a href="https://stackoverflow.com/questions/32558941/render-razor-view-to-string-in-asp-net-core/32577016#32577016">here</a> and <a href="http://www.codelocker.net/30362/dot-net-convert-or-render-an-mvc-view-to-a-string/" rel="noreferrer">here</a> and <a href="https://stackoverflow.com/questions/483091/render-a-view-as-a-string">here</a></p>
  
  <p><strong>NOTE</strong>
  I need the solution to get the view converted to <code>string</code> in .NET Core, regardless same code got converted, or another way that can do it.</p>