title: C#, ASP.NET MVC / MVC2: Url.Action - Link with specific parameters, leaving one out
body: <p>I have the following code:</p>
  
  <pre><code>Url.Action("Index", "Home",  new {param1 = Model.Param1, param2 = Model.Param2} )
  </code></pre>
  
  <p>Now, if Param2 is NullOrEmpty I want to link using the following code:</p>
  
  <pre><code>Url.Action("Index", "Home",  new {param1 = Model.Param1} )
  </code></pre>
  
  <p>Is there an easier way to do this or will I need to do something like this:</p>
  
  <pre><code>string myLinkVal = (Model.Param2 == string.IsNullOrEmpty()) ? 
      Url.Action("Index", "Home",  new {param1 = Model.Param1} ) :
      Url.Action("Index", "Home",  new {param1 = Model.Param1, param2 = Model.Param2} );
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Thank you for your answer. The Problem is, that I have the empty param in my link.</p>
  
  <p>I have the following routes:</p>
  
  <pre><code>"/{param1}/{param2}/{controller}/{action}/{id}"
  ...
  "/{param1}/{controller}/{action}/{id}"
  </code></pre>
  
  <p>When Param2 is empty I want to use the other route (the one without param2).</p>
  
  <p>Currently I can only archieve this by using</p>
  
  <pre><code>new {param1 = Model.Param1, param2 = Model.Param2}
  </code></pre>
  
  <p>or</p>
  
  <pre><code>new {param1 = Model.Param1}
  </code></pre>
  
  <p>Then the correct route is picked.</p>