title: Routing optional parameters in ASP.NET MVC 5
body: <p>I am creating an ASP.NET MVC 5 application and I have some issues with routing. We are using the attribute <code>Route</code> to map our routes in the web application. I have the following action:</p>
  
  <pre><code>[Route("{type}/{library}/{version}/{file?}/{renew?}")]
  public ActionResult Index(EFileType type, 
                            string library, 
                            string version, 
                            string file = null, 
                            ECacheType renew = ECacheType.cache)
  {
   // code...
  }
  </code></pre>
  
  <p>We only can access this URL if we pass the slash char <code>/</code> in the end of <code>url</code>, like this:</p>
  
  <pre><code>type/lib/version/file/cache/
  </code></pre>
  
  <p>It works fine but does not work without <code>/</code>, I get a <code>404</code> not found error, like this</p>
  
  <pre><code>type/lib/version/file/cache
  </code></pre>
  
  <p>or this (without optional parameters):</p>
  
  <pre><code>type/lib/version
  </code></pre>
  
  <p>I would like to access with or without <code>/</code> char at the end of <code>url</code>. My two last parameters are optional.  </p>
  
  <p>My <code>RouteConfig.cs</code> is like this:</p>
  
  <pre><code>public class RouteConfig
  {
      public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
          routes.MapMvcAttributeRoutes();
      }
  }
  </code></pre>
  
  <p>How can I solve it? Make the slash <code>/</code> be optional too?</p>