Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Default values for attribute routing are ignored, after migrating from ASP.NET Core RC2 to RTM #4956

Closed
lalibi opened this issue Jul 4, 2016 · 3 comments

Comments

@lalibi
Copy link

lalibi commented Jul 4, 2016

Code like the following, used to work with RC2, and the default value (=1) was honored.

[Route("[controller]/[action]")]
public class FooController : Controller
{
    [HttpGet("{id:int=1}")]
    public IActionResult Bar(int id)
    {
        ViewData["Message"] = $"Id: {id}";
        return View();
    }
}

With RC2, URLs /Foo/Bar/1 and /Foo/Bar gave the same results. After upgrading To RTM, /Foo/Bar gives a 404 error.

@javiercn
Copy link
Member

javiercn commented Jul 5, 2016

Its a known bug in atribute routing. The workaround is to use two routes and provide the default value in the method parameter. See aspnet/Routing#324

@Eilon Eilon added the duplicate label Jul 5, 2016
@Eilon Eilon closed this as completed Jul 5, 2016
@ststeiger
Copy link

Instead of fixing the bug...

@javiercn
Copy link
Member

javiercn commented Feb 7, 2018

This bug was fixed as of aspnet/Routing@ffa0ee5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants