title: How to call a PartialView from outside the controller in ASP.NET 5
body: <p>I want to create a common message box method that can be called throughout my <code>ASP.NET 5</code> application </p>
  
  <p>The code should be something like this:</p>
  
  <pre><code>public class WebHelper
  {
      public static IActionResult MessageBox(string message)
      {
          return PartialView("~/Views/Shared/_MessageBox.cshtml", message);
      }
  }
  </code></pre>
  
  <p>And then in my controller call:</p>
  
  <pre><code>return WebHelper.MessageBox("Hallo world");
  </code></pre>
  
  <p>instead of what I am currently doing of :</p>
  
  <pre><code> return PartialView("~/Views/Shared/_MessageBox.cshtml", "Hallo world");
  </code></pre>
  
  <p>However  PartialView is bound to the controller so it seems I cannot use it outside the controller.</p>
  
  <p>I tried to use <a href="https://stackoverflow.com/questions/11642815/render-mvc-partialview-into-signalr-response">Answers 1</a> <a href="https://stackoverflow.com/questions/30572619/render-partial-view-without-creating-an-actionresult">Answers 2</a> which are solutions for <code>ASP.NET 4</code> but they don't work in <code>ASP.NET 5</code> e.g.</p>
  
  <pre><code> public string RenderPartialViewToString(string viewName, object model)
      {
          this.ViewData.Model = model;
          try
          {
              using (StringWriter sw = new StringWriter())
              {
                  ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(this.ControllerContext, viewName);
                  ViewContext viewContext = new ViewContext(this.ControllerContext, viewResult.View, this.ViewData, this.TempData, sw);
                  viewResult.View.Render(viewContext, sw);
  
                  return sw.GetStringBuilder().ToString();
              }
          }
          catch (System.Exception ex)
          {
              return ex.ToString();
          }
      }
  </code></pre>
  
  <p>as I can't find the  <code>ViewEngines.Engine</code>  in the <code>ASP.NET 5</code> namespaces.</p>
  
  <p>Question:
  What is the simplest way to solve my problem in `ASP.NET 5? Providing the method and calling method code</p>