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

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -