Regex in Route attribute - RESTful API ASP.NET Web API

自古美人都是妖i 提交于 2019-12-01 14:29:41

For nullable second parameter, write your route template as

[Route("api/recommendations/date/{startDate:datetime:regex(\\d{2}-\\d{2}-\\d{4})}/{endDate:datetime:regex(\\d{2}-\\d{2}-\\d{4})?}")]

And you should provide with a default value for nullable parameter

public IEnumerable<Recommendation> GetRecommendationByDate(DateTime startDate, DateTime? endDate = null)

For slashes, slash is used to separate url segments, which means one single segment can't contain slash unless they are encoded.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!