title: MVC routing - different urls to the same action
body: <p>I have backbone.js framework at client side that performs POSTs to the following urls to create/update some entity:<br>
  <code>controller/action</code> - for creating a new<br>
  <code>controller/action/{id}</code> - for updating an existing one  </p>
  
  <p>I want a single action <code>Save</code> to process both operations and perform entity creation/updation depending on the Id value of the incoming model that is listed below:  </p>
  
  <pre><code>public class TestModel
  {
      public int? Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>The JSON model being posted looks like: <code>{ id: 123, name: "some name" }</code><br>
  Thus I want to have a single controller action <code>Save</code> and to tune the route table so it accepts both <code>controller/action</code> and <code>controller/action/{id}</code> requests for the action Save.
  I've racked my brain trying to achieve it.<br>
  My action looks like:  </p>
  
  <pre><code>[HttpPost]
  public ActionResult Save(TestModel model)
  {
      // do something
  }
  </code></pre>
  
  <p>The following route configs didn't make it work:<br>
  1.</p>
  
  <pre><code>    routes.MapRoute(
          name: "Test.Save1",
          url: "api/test/data",
          defaults: new { controller = "Test", action = "Save" }
      );
  
      routes.MapRoute(
          name: "Test.Save2",
          url: "api/test/data/{id}",
          defaults: new { controller = "Test", action = "Save", id = UrlParameter.Optional }
      );
  </code></pre>
  
  <p>Works for /api/test/data, returns 404 on posting to /api/test/data/123</p>
  
  <p>2.</p>
  
  <pre><code>    routes.MapRoute(
          name: "Test.Save",
          url: "api/test/data/{id}",
          defaults: new { controller = "Test", action = "Save", id = UrlParameter.Optional }
      );
  </code></pre>
  
  <p>Works for /api/test/data, returns 404 on posting to /api/test/data/123</p>
  
  <p>3.</p>
  
  <pre><code>    routes.MapRoute(
          name: "Test.Save",
          url: "api/test/data/{*pathInfo}",
          defaults: new { controller = "Test", action = "Save" }
      );
  </code></pre>
  
  <p>Works for /api/test/data, returns 404 on posting to /api/test/data/123</p>
  
  <p>I probably can guess why it gives error, but more important question is how to make it work? Thank you!</p>