- 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.
- 異構(gòu)基因共表達(dá)網(wǎng)絡(luò)的分析方法
- Django 2 by Example
- 農(nóng)產(chǎn)品物聯(lián)網(wǎng)研究與應(yīng)用
- 局域網(wǎng)組建、管理與維護(hù)項(xiàng)目教程(Windows Server 2003)
- Building RESTful Web Services with Spring 5(Second Edition)
- 網(wǎng)絡(luò)安全技術(shù)與解決方案(修訂版)
- 區(qū)塊鏈輕松上手:原理、源碼、搭建與應(yīng)用
- 物聯(lián)網(wǎng)通信技術(shù)
- 物聯(lián)網(wǎng)技術(shù)與應(yīng)用
- Microsoft Power Platform Enterprise Architecture
- 深入理解Nginx:模塊開(kāi)發(fā)與架構(gòu)解析
- 數(shù)據(jù)血緣分析原理與實(shí)踐
- 華為HCIA-Datacom認(rèn)證指南
- 商業(yè)的本質(zhì)和互聯(lián)網(wǎng)
- RestKit for iOS