title: How to pass two parameters from view to controller but display only one in url?
body: <p>I'm building an app in MVC 4 and I'm stuck on one thing. </p>
  
  <p>I have a controller and action:</p>
  
  <pre><code>public ActionResult Details(string pattern, int id)
  {
      Post post = repository.GetPostById(id);
  
      return View(post);
  }
  </code></pre>
  
  <p>And in the view:</p>
  
  <pre><code>&lt;div class="innerbody"&gt;
      @Model.Description @Html.ActionLink("Czytaj dalej...", "Details", new { id = Model.PostId, pattern = Model.ShortUrl})
  &lt;/div&gt;
  </code></pre>
  
  <p>Now what I'm trying to accomplish is that the url will be:</p>
  
  <pre><code>www.mysite.com/blog/pattern
  </code></pre>
  
  <p>Without <code>id</code>. 'pattern' is <code>ShortUrl</code> extracted from post title.</p>
  
  <p>I've tried adding these different routes to RouteConfig:</p>
  
  <pre><code>routes.MapRoute(
      name: "Details",
      url: "{Controller}/{pattern}",
      defaults: new {controller = "Blog", action = "Details", pattern = "", id = UrlParameter.Optional}
  ); 
  </code></pre>
  
  <p>or</p>
  
  <pre><code>routes.MapRoute(
      name: "Details",
      url: "{Controller}/{pattern}",
      defaults: new {controller = "Blog", action = "Details", pattern = ""}
  );
  </code></pre>
  
  <p>But it keeps throwing the error:</p>
  
  <blockquote>
    <p><em>The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(System.String, Int32)' in 'MyBlog.Controllers.BlogController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.</em></p>
  </blockquote>
  
  <p>I think I can't catch this 'routing' thing... How could I accomplish this task?</p>