Route parameter with slash “/” in URL

后端 未结 4 2022
盖世英雄少女心
盖世英雄少女心 2020-12-01 13:32

I know you can apply a wildcard in the route attribute to allow / such as date input for example:

[Route(\"orders/{*orderdate}\")]
4条回答
  •  悲哀的现实
    2020-12-01 14:11

    You can use the following URI [Route("orders/{DD:int}/{MM:int}/{YY:int}}/customers")] and then use a custom model binder to take DD/MM/YY and turn them into a date that you can bind in your action method.

    You can choose how you want to deal with constraints (go stricter with regex's) or use validation and return 400 if it doesn't match.

    The simpler approach is, to take the Day/Month/Year and put it together in code.

    Here is a link for dealing with modelbinding.

提交回复
热议问题