Multiple Optional Parameters with ServiceStack.Net

前端 未结 1 842
走了就别回头了
走了就别回头了 2020-12-10 03:31

I\'m trying to implement a service with Multiple Optional Parameters using ServiceStack.Net

At the moment my route looks like this

Routes.Add

        
相关标签:
1条回答
  • 2020-12-10 03:51

    When your Route requirements start to get too complicated it will eventually become easier just to add a wild card path so you can parse the rest of the querystring yourself. i.e. in this case since the first part of the querystring remains constant you can add a wild card mapping to store the variable parts of the querystring, i.e:

    Routes.Add("/save/{Year}/{Week}/{DaysString*}");
    

    ServiceStack will still populate the partial DTO with the Year and Week fields (as well any fields that were passed in the querystring). The remaining variable parts of the url is stored in the DaysString which you are then free to parse yourself manually. So the above mapping will be able to match urls like:

    /save/2010/12/Monday/4/Tuesday/6?Wednesday=7

    And populate the following variables in your Request DTO:

    • Year: 2010
    • Week: 12
    • Wednesday: 7
    • DaysString: Monday/4/Tuesday/6
    0 讨论(0)
提交回复
热议问题