I am trying to change this convention based route:
routes.MapRoute(
\"MovieByReleaseDate\",
\"movies/released/{year}/{month}\",
new { controller
You can use multiple [Route] attributes coupled with nullable parameters to achieve your goal.
[HttpGet]
[Route("movies/released/")]
[Route("movies/released/{year}")]
[Route("movies/released/{year}/{month}")]
public string Test(int? year = 2018, int? month = 1)
{
return "The year is " + year;
}
When you send a request to movies/released without a year, the default value is used for the year. When you send a request to movies/released/2000, the URL parameter overrides the default value.