title: MVC Alternative routing is failing with optional parameter
body: <p>I am trying to implement alternative routing in my <strong>MVC 5</strong> web app.</p>
  
  <p>I have the controller code:</p>
  
  <pre><code>namespace MyMvcProject.Web.Controllers
  {
      [RoutePrefix("account")]
      public class AccountController : Controller {
  
  
          [Route("{param}")]
          [Authorize]
          public ActionResult Index(string param = null) {
  
  ...
  </code></pre>
  
  <p>which works great when hitting the url: <code>http://example.com/account/testparam</code>.
  However, I would like to be able to have the value <code>param</code> as an optional parameter.</p>
  
  <p>I have tried changing <code>[Route("{param}")]</code> to <code>[Route("{param}*")]</code> but then the <code>Index()</code> method is never entered. I have also tried changing it to <code>[Route("{param:string=Test}")]</code> but I get a routing runtime error with the term <code>string</code>.</p>
  
  <p>My <code>RoutConfig.cs</code> contains:</p>
  
  <pre><code> public static void RegisterRoutes(RouteCollection routes) 
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
              routes.MapMvcAttributeRoutes();
  
              routes.MapRoute(
                  name: "Default",
                  url: "{controller}/{action}/{param}",
                  defaults: new { controller = "Home", action = "Index", param = UrlParameter.Optional }
              );
          }
  </code></pre>
  
  <p>Does anyone have any idea how I could force <code>Index()</code> to have an optional parameter using this alternative routing syntax? It's quite useful in other parts of my app, so I'd like to keep the <code>RoutePrefix</code> and <code>Route</code> decorators.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I'm still trying to figure this out, so I changed my route decorator to <code>[Route("{param:int=0}")]</code> and my constructor to <code>public ActionResult Index(int id)</code> and it works as expected (i.e., <code>http://example.com/account</code> behaves as if <code>http://example.com/account/0</code> was entered. This is exactly what I want, only using <code>string</code> datatypes. </p>
  
  <p>When I change the decorator to: <code>[Route("{id:string=\"\"}")]</code> and the constructor to <code>public ActionResult Index(string id)</code> and I see the runtime error: </p>
  
  <blockquote>
    <p>The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'.</p>
  </blockquote>