title: Passing an instance of a class as an argument to the action/method of Url.Action
body: <p>My goal is to achieve the following:</p>
  
  <ol>
  <li>While on an ASP.NET page, the user selects a server from a list of <code>Server</code> objects.</li>
  <li>The user clicks a button to export information about that server.</li>
  <li>Clicking the button executes a C# method <code>ExportServerInfo()</code> with the current <code>Server</code> object (<code>Model.Servers[i]</code>) passed to it.</li>
  </ol>
  
  <p>The controller has the method:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public void ExportServerInfo(Server id)
  {
      // Do something with the Server
      System.Diagnostics.Debug.WriteLine(id.Name);
      System.Diagnostics.Debug.WriteLine(id.RamCapacity);
  }
  </code></pre>
  
  <p>The view is a CSHTML file using Razor. This is the code for the button:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="col-md-12" align="right"&gt;
      &lt;a href="@Url.Action("ExportServerInfo", "ServerList", new { id = Model.Servers[i] })" class="btn btn-primary"&gt;
          &lt;span class="glyphicon glyphicon-download-alt" aria-hidden="true"&gt;&lt;/span&gt;
           @MainResource.SomeLocalizationString
      &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>HTML generated: <code>&lt;a href="/ServerList/ExportServerInfo/ProjectName.ViewModels.Server" class=...&gt;</code></p>
  
  <p>When the button is clicked, the method <code>ExportServerInfo()</code> in the ServerListController class should be called with the selected <code>Server</code> as the only argument. Instead, the user is brought to <code>localhost:56789/ServerList/ExportServerInfo/ProjectName.ViewModels.Server</code> with an HTTP 404 error from the web server because it can't find it; that string alone doesn't indicate which server it is. The method isn't called at all. A similar solution I tried brought the user to a blank page with the above as a query string in the URL instead.</p>
  
  <p>When the user clicks the button, the method should be called, but instead, the user gets moved to a page (which 404s) and the method isn't called.</p>
  
  <hr>
  
  <p>The method is executed if the action has no argument/parameter:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="col-md-12" align="right"&gt;
      &lt;a href="@Url.Action("ExportServerInfo", "ServerList")" class="btn btn-primary"&gt;
          &lt;span class="glyphicon glyphicon-download-alt" aria-hidden="true"&gt;&lt;/span&gt;
           @MainResource.SomeLocalizationString
      &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>HTML generated: <code>&lt;a href="/ServerList/ExportServerInfo" class=...&gt;</code></p>
  
  <p>The user clicks the button ("visiting" <code>/ServerList/ExportServerInfo</code>) but stays on the page, and the method runs (with no parameters). But the method must have a parameter to pass the <code>Server</code> back to the controller.</p>
  
  <hr>
  
  <p>Also, for some reason, the look of the button is fine when it works, but the highlight colours are a little off with the wrong implementation.</p>
  
  <p><strong>tl;dr:</strong> Argument isn't passed to the method, method never runs, user is routed to 404 page. Method needs a <code>Server</code> passed into it.</p>