title: MVC 4 Partial with separate Controller and View
body: <p>I've developed ASP.NET Forms for some time and now am trying to learn MVC but it's not making total sense how to get it to do what I want. Perhaps I need to think about things differently. Here is what I'm trying to do with a made up example:</p>
  
  <p>Goal - Use a partial file, which can be placed anywhere on the site which will accept a parameter. That parameter will be used to go to the database and pass back the resulting model to the view. The view will then display one or more of the models properties.</p>
  
  <p>This isn't my code, but shows what I'm trying to do.</p>
  
  <p>File: Controllers/UserController.cs</p>
  
  <pre><code>[ChildActionOnly]
  public ActionResult DisplayUserName(string userId)
  {
  MyDataContext db = new MyDataContext()
  
  var user = (from u in db.Users where u.UserId = userId select u).FirstOrDefault();
  
  return PartialView(user);
  }
  </code></pre>
  
  <p>File: Views/Shared/_DisplayUserName.cs</p>
  
  <pre><code>@model DataLibrary.Models.User
  
  &lt;h2&gt;Your username is: @Model.UserName&lt;/h2&gt;
  </code></pre>
  
  <p>File: Views/About/Index.cshtml</p>
  
  <pre><code>@{
      ViewBag.Title = "About";
  }
  
  &lt;h2&gt;About&lt;/h2&gt;
  
  {Insert Statement Here}
  </code></pre>
  
  <p>I know at this point I need to render a partial called DisplayUserName, but how does it know which view to use and how do I pass my userId to the partial?</p>
  
  <p>It's what I expect is a very basic question, but I'm yet to find a tutorial which covers this.</p>
  
  <p>Thanks in advance for your help.</p>