- Hands-On Full:Stack Web Development with ASP.NET Core
- Tamir Dresher Amir Zuker Shay Friedman
- 176字
- 2021-06-10 19:37:30
Constraints
Inline constraints inside the routing attributes are used by placing a colon with the constraint name :constraint-name after the route parameter name, where constraint-name is a constraint that you define by creating a class that implements the IRouteConstraint interface, or simply by using one of the built-in constraints specified in the ASP.NET documentation, available at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?highlight=routing#route-constraint-reference.
The following example shows how we can add a search method to our ProductsController that searches by the date that the product was posted online. The URL for this action must constrain the date parameter to datetime formats only; therefore, we will use the datetime constraint like this:
[HttpGet("search/{date:datetime}/{keyword}/")]
public string[] Search(string date, string keyword)
{
return new[]
{
$"Date: {date}, keyword: {keyword}"
};
}
The routing infrastructure in ASP.NET Core is very sophisticated, and there are plenty more features out of the scope of this book that therefore aren't covered. For more details about the routing capabilities in ASP.NET Core, refer to the documentation at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing.
- Application Development with Qt Creator(Second Edition)
- Cisco OSPF命令與配置手冊
- 物聯網智慧安監技術
- 物聯網網絡安全及應用
- SEO 20日
- INSTANT PhpStorm Starter
- SD-WAN架構與技術(第2版)
- WordPress 5 Complete
- Microservice Patterns and Best Practices
- 網絡設計與應用(第2版)
- 4G小基站系統原理、組網及應用
- Hands-On Microservices with Node.js
- AWS Lambda Quick Start Guide
- Web用戶查詢日志挖掘與應用
- Building Microservices with Spring