title: How to render partials from another Controller
body: <p>If I have a HomeController displaying its Index view, how would I proceed in order to have the Index view imbed a UserControl from another Controller?</p>
  
  <p>Here's a look at the content of the Home/Index View:</p>
  
  <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %&gt;
  
  &lt;asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server"&gt;
      &lt;%=Resources.Global.HomeTitle %&gt;
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server"&gt;
      &lt;h2&gt;&lt;%= Html.Encode(ViewData["Message"]) %&gt;&lt;/h2&gt;
      &lt;p&gt;&lt;%=Resources.Global.HomeIndex %&gt;&lt;/p&gt;
  
      &lt;h3&gt;Partial title&lt;/h3&gt;
      &lt;% Html.RenderPartial("~/Views/OtherController/SomeAction.ascx"); %&gt;
  
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>Here's the OtherController content:</p>
  
  <pre><code>public class OtherController : BaseController
  {
      private readonly IRepositoryContract&lt;SomeType&gt; repo = new SomeTypeRepository();
  
      public ActionResult SomeAction()
      {
          IQueryable&lt;SomeType&gt; items = repo.GetAllItems();
          return View("SomeAction", items);
      }
  }
  </code></pre>
  
  <p>This gives me an NullReferenceException since the Controller is never being called by the RenderPartial() method. Changing the following line</p>
  
  <pre><code>&lt;% Html.RenderPartial("~/Views/OtherController/SomeAction.ascx"); %&gt;
  </code></pre>
  
  <p>by this</p>
  
  <pre><code>&lt;% Html.RenderPartial("~/Views/OtherController/SomeAction.ascx",((ViewResult) new OtherController().SomeAction()).ViewData.Model); %&gt;
  </code></pre>
  
  <p>works, but it sure is ugly as hell. There has to be a better way to imbed partials from another controller?</p>
  
  <p><strong>Update :: Solution found</strong></p>
  
  <p>Here's the code after implementing <a href="https://stackoverflow.com/users/59301/adrian-grigore">Adrian Grigore</a>'s solution:</p>
  
  <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %&gt;
  &lt;%@ Import Namespace="Microsoft.Web.Mvc"%&gt;
  
      &lt;asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server"&gt;
          &lt;%=Resources.Global.HomeTitle %&gt;
      &lt;/asp:Content&gt;
  
      &lt;asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server"&gt;
          &lt;h2&gt;&lt;%= Html.Encode(ViewData["Message"]) %&gt;&lt;/h2&gt;
          &lt;p&gt;&lt;%=Resources.Global.HomeIndex %&gt;&lt;/p&gt;
  
          &lt;h3&gt;Partial title&lt;/h3&gt;
          &lt;% Html.RenderAction("SomeAction","OtherController"); %&gt;
  
      &lt;/asp:Content&gt;
  </code></pre>