hi
i was reading about MapControllerRoute() what i understansed that i has two main processes
- defining the Route Templates and there crosponding pattern
- add thos route template to the routes table (that the UseRouting() use when matching incomming request with the route template in the route table);
- Run the UseEndponints() that excutes the suitable action according to the matched url
what i want to ask is the part of the defining the route template and there crospnding pattern, the app includes only one patten that are defined throught the MapControllerRoute() like below code , then i have 3 controller action in my Homecontroller class then haw many template will be added to the table
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
Jignesh KumarPosted Sep 23, 2024, 8:05 AM
Hello Mina,
If you want to understand route table with debugging, you can add the below line in your code and debug,
MVC:
MVC Core :
mina shakerPosted Sep 22, 2024, 8:56 PM
@Sam Hobbs then which one is correct , that why i dont like to read from the docs is all misleading and it is not for begginers
Sam HobbsPosted Sep 22, 2024, 8:23 PM
The
MapControllerRoutedocumentation, as in:ControllerEndpointRouteBuilderExtensions.MapControllerRoute Method (Microsoft.AspNetCore.Builder) | Microsoft Learn
https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.controllerendpointroutebuilderextensions.mapcontrollerroute?view=aspnetcore-8.0
I think is misleading. The documentation says that it Adds endpoints (plural). Yet the following:
Routing to controller actions in ASP.NET Core
https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-8.0
Says
MapControllerRouteis used to create a single route.Does (not dose) that help?
mina shakerPosted Sep 22, 2024, 7:56 PM
@Jignesh Kumar i do understand this but what i dont understand how many route will be added to the route table
Jignesh KumarPosted Sep 22, 2024, 9:36 AM
Hello Mina,
Let's take an example for your routing,
Create Home controller with Index method and Details method which take id as integer parameter,