I have the following code in my controller class
[Route("movies/released/{{year}}/{{month:regex(\\d{2}):range(1,12)}}")]
public ActionResult ByReleaseDate(int year, int month)
{
return Content(year + "/" + month);
}
And have the following code in the startup class
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "MoviesByReleaseDate",
pattern: "{controller=Movies}/{action=ByReleaseDate}/{year}/{month}") ;
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
I am trying to do attribute routing where as when I type in the URL
https://localhost:44334/movies/released/2022/06
it should just display 2022/06 on page. But instead its throwing 404 "not found" error. What am I doing wrong here? I'm using .NET Core 5.0
[Route("movies/released/{year:int}/{month:int}")]- does it work now?