Optional Parameters in Web Api Attribute Routing

后端 未结 3 1545
小鲜肉
小鲜肉 2020-12-01 11:56

I want to handle POST of the following API-Call:

/v1/location/deviceid/appid

Additional Parameter are coming from the Post-Body.

This al

3条回答
  •  无人及你
    2020-12-01 12:24

    Converting my comment into an answer to complement @Kiran Chala's answer as it seems helpful for the audiences-

    When we mark a parameter as optional in the action uri using ? character then we must provide default values to the parameters in the method signature as shown below:

    MyMethod(string name = "someDefaultValue", int? Id = null)

提交回复
热议问题