title: asp.net mvc - Using multiple URLs to the same action
body: <p>I have a controller called <code>TaskListsController</code> with an action called <code>Edit</code>.</p>
  
  <p>The <code>Edit</code> action accepts a nullable int parameter. If it receives null, it adds a <code>TaskList</code>. If it receives an int, it edits the <code>TaskList</code> with the same ID. The logic is almost identical in each case.</p>
  
  <p>I would like to configure my routing in such a way that the URL 'TaskLists/Add' maps to the <code>Edit</code> action with null as the parameter, and the URL 'TaskLists/Edit/{id}' maps to <code>Edit</code> and passes it the ID in the URL.</p>
  
  <p>I can get this to work from the point of view of entering URLs in the browser and having them routed to the action correctly, but where it's falling down is where the system generates URLs from <code>Html.ActionLink</code>.</p>
  
  <p>I am generating 'Add' links using:</p>
  
  <pre><code>Html.ActionLink("Add task list", "Edit", "TaskLists")
  </code></pre>
  
  <p>And I'm generating 'Edit' links using:</p>
  
  <pre><code>Html.ActionLink(taskList.Name, "Edit", new { Id = taskList.Id })
  </code></pre>
  
  <p>..where <code>taskList</code> is an instance of the <code>TaskList</code> class.</p>
  
  <p>If I use this routing:</p>
  
  <pre><code>routes.MapRoute(
                  "TaskLists/Add", // Route name
                  "TaskLists/Add", // URL with parameters
                  new { controller = "TaskLists", action = "Edit" });
  
              routes.MapRoute(
                  "TaskLists/Edit/{id}", // Route name
                  "TaskLists/Edit/{id}", // URL with parameters
                  new { controller = "TaskLists", action = "Edit", id = UrlParameter.Optional });
  </code></pre>
  
  <p>...the 'Add' link is generated correctly ('TaskLists/Add') but the 'Edit' link comes out 'TaskLists/Add?Id=1'.</p>
  
  <p>If I put the routing commands the other way around:</p>
  
  <pre><code>routes.MapRoute(
                  "TaskLists/Edit/{id}", // Route name
                  "TaskLists/Edit/{id}", // URL with parameters
                  new { controller = "TaskLists", action = "Edit", id = UrlParameter.Optional });
  
              routes.MapRoute(
                  "TaskLists/Add", // Route name
                  "TaskLists/Add", // URL with parameters
                  new { controller = "TaskLists", action = "Edit" });
  </code></pre>
  
  <p>...then the 'Edit' links are generated correctly ('TaskLists/Edit/x'), but the 'Add' links comes out 'TaskLists/Edit'.</p>
  
  <p>Is there a way I can have my cake and eat it?</p>