c# - WebApi - Convert null string into null value -


what best way convert 'null' string (passed url) null value in webapi using attribute routing?

url sample:

localhost:29365/api/mycontroller/test/first/null/third

api controller method sample:

[httpget] [route("~/api/mycontroller/test/{first}/{second}/{third}")] public void test(string first, string second, string third) { ... } 

well option comparing if string value null. seems terrible.

why not try passing parameters instead.

[httpget] [route("~/api/mycontroller/test")] public void test(string first = null, string second = null, string third = null) { ... } 

url sample

localhost:29365/api/mycontroller/test?first=myfirstvalue&third=mythirdvalue

by not supplying second value null default.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -