id-parameter of string type doesn't have optional attribute

Imported from the CodePlex archive for reference purposes. Support for MvcCodeRouting has ended.

Commented on
Hello.

I have a controller with string parameter on action method:
public class TestController : Controller
{
    public ActionResult GetSmth(string id)
    {
        if (String.IsNullOrEmpty(id))
            return Content("Empty");
        else
            return Content("NonEmpty");
    }
}
and routes registred as:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapCodeRoutes(
    typeof(DemoApp.Controllers.HomeController),
    new CodeRoutingSettings
    {
        UseImplicitIdToken = true
    }
);
It produces next line to the routes.axd output:
routes.MapRoute(null, "Test/GetSmth/{id}", new { controller = "Test", action = "GetSmth" }, new[] { "DemoApp.Controllers" });
I need the Empty content from the test controller, so I use:
@Url.Action("GetSmth", "~~Test")
but null returned instead of /Test/GetSmth

I think that because id = UrlParameter.Optional was not set to the route configuration.

If I use standard ASP.NET MVC routing mechanism, then Url.Action("GetSmth", "Test") works as expected (/Test/GetSmth url as result).
Commented on link
Use a default value, e.g. string id = null or string id = "".
Commented on link
Thanks, Max.

Its works!
public class TestController : Controller
{
    public ActionResult GetSmth(string id = null)
    {
        if (String.IsNullOrEmpty(id))
            return Content("Empty");
        else
            return Content("NonEmpty");
    }
}