title: Calling controller action method directly from Razor View
body: <p>I looked around and couldn't find an easy solution.</p>
  
  <p>I've tried <code>@GetUserName</code> which doesn't work.<br>
  I've tried <code>@ { GetUserName</code> which doesn't work.</p>
  
  <p>There has to be an easy way to call a method from the razor view engine.</p>
  
  <p>It is within a <code>foreach</code> loop.</p>
  
  <p>I need <code>GetUserName(item.userID)</code></p>
  
  <p>The below code is in my controller:</p>
  
  <pre><code>[ChildActionOnly]
  public string GetUserName(int userID)
  {
       ProPit_User user = db.ProPit_User.Find(userID);
  
       return user.username;
  }
  </code></pre>