- 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.
- Oracle SOA Suite 11g Performance Tuning Cookbook
- HTML5 Game development with ImpactJS
- 通信簡史:從信鴿到6G+
- 面向物聯網的嵌入式系統開發:基于CC2530和STM32微處理器
- 物聯網安全技術
- NB-IoT物聯網技術解析與案例詳解
- 網絡安全應急響應技術實戰
- Building Web Applications with ArcGIS
- Working with Legacy Systems
- Learning Windows 8 Game Development
- 語音信號處理及Blackfin DSP實現
- 網絡工程實施技術與方案大全
- 網絡綜合布線(第2版)
- INSTANT LinkedIn Customization How-to
- 智能物聯網:區塊鏈與霧計算融合應用詳解