All-Star
53661 Points
24018 Posts
Jul 04, 2020 01:51 PM|mgebhard|LINK
MLT111 thank you But I need a special route for product . endpoints.MapControllerRoute( name: "Product", pattern: "{id}/{title}", defaults: new { controller = "Product", action = "Index" } ); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}" );
thank you
But I need a special route for product .
endpoints.MapControllerRoute( name: "Product", pattern: "{id}/{title}", defaults: new { controller = "Product", action = "Index" } ); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}" );
Use an int constraint.
app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "Product", pattern: "{id:int}/{title}", defaults: new { controller = "Product", action = "Index" }); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); });
All-Star
53661 Points
24018 Posts
Re: url friendly in mvc core 3
Jul 04, 2020 01:51 PM|mgebhard|LINK
Use an int constraint.
app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "Product", pattern: "{id:int}/{title}", defaults: new { controller = "Product", action = "Index" }); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); });