Skip to content

Commit 33836f9

Browse files
authored
Fix a couple of small MVC routing issues (#18496)
1 parent 0bbcc3a commit 33836f9

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

aspnetcore/mvc/controllers/routing.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"
9292
> Routing is configured using the <xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseRouting*> and <xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints*> middleware. To use controllers:
9393
>
9494
> * Call <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllers*> inside `UseEndpoints` to map [attribute routed](#ar) controllers.
95-
> * Call <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute*> or <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapAreaControllerRoute*>, to map [conventionally routed](#cr) controllers.
95+
> * Call <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute*> or <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapAreaControllerRoute*>, to map both [conventionally routed](#cr) controllers and [attribute routed](#ar) controllers.
9696
9797
<a name="routing-conventional-ref-label"></a>
9898
<a name="crd"></a>
@@ -257,7 +257,7 @@ REST APIs should use attribute routing to model the app's functionality as a set
257257

258258
Attribute routing uses a set of attributes to map actions directly to route templates. The following `StartUp.Configure` code is typical for a REST API and is used in the next sample:
259259

260-
[!code-csharp[](routing/samples/3.x/main/StartupApi.cs?name=snippet)]
260+
[!code-csharp[](routing/samples/3.x/main/StartupAPI.cs?name=snippet)]
261261

262262
In the preceding code, <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllers*> is called inside `UseEndpoints` to map attribute routed controllers.
263263

@@ -272,10 +272,7 @@ The `HomeController.Index` action is run for any of the URL paths `/`, `/Home`,
272272

273273
This example highlights a key programming difference between attribute routing and [conventional routing](#cr). Attribute routing requires more input to specify a route. The conventional default route handles routes more succinctly. However, attribute routing allows and requires precise control of which route templates apply to each [action](#action).
274274

275-
In the following code:
276-
277-
* The controller name and action names play **no** role in which action is matched.
278-
* Matches the same URLs as the previous example:
275+
With attribute routing, the controller and action names play no part in which action is matched, unless [token replacement](#routing-token-replacement-templates-ref-label) is used. The following example matches the same URLs as the previous example:
279276

280277
[!code-csharp[](routing/samples/3.x/main/Controllers/MyDemoController.cs?name=snippet)]
281278

@@ -563,8 +560,6 @@ Attribute routes support the same inline syntax as conventional routes to specif
563560

564561
In the preceding code, `[HttpPost("product/{id:int}")]` applies a route constraint. The `ProductsController.ShowProduct` action is matched only by URL paths like `/product/3`. The route template portion `{id:int}` constrains that segment to only integers.
565562

566-
[!code-csharp[](routing/samples/3.x/main/Controllers/HomeController.cs?name=snippet24)]
567-
568563
See [Route Template Reference](xref:fundamentals/routing#route-template-reference) for a detailed description of route template syntax.
569564

570565
<a name="routing-cust-rt-attr-irt-ref-label"></a>

aspnetcore/mvc/controllers/routing/samples/3.x/main/Controllers/HomeController.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
//#define First
55
//#define Second
66
//#define Third
7-
//#define Forth
87

9-
#define Five
8+
#define Forth
109

1110
using Microsoft.AspNetCore.Mvc;
1211
using Microsoft.Docs.Samples;
@@ -94,16 +93,6 @@ public IActionResult About()
9493
}
9594
}
9695
#endregion
97-
#elif Five
98-
#region snippet24
99-
public class HomeController : Controller
100-
{
101-
public IActionResult Index()
102-
{
103-
return ControllerContext.MyDisplayRouteInfo();
104-
}
105-
}
106-
#endregion
10796
#endif
10897
}
10998

0 commit comments

Comments
 (0)