asp.net web api - Pass null String to Web API 2 (Visual Studio 2013) -
i have method this:
public ienumerable<test> gettest(int32 idtest, string codtest, int value)
and test client this:
client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json")); response = await client.getasync("test/gettest/0/null/1/");
i need pass null in second parameter (that not optional), on server side string "null" inside , not null value. not put conversion functions each parameter. see works if put [frombody] attribute 1 parameter, if set [frombody] string parameters internal server error.
many thanks.
you typically shouldn't have optional parameters in middle of route.
i recommend changing order of parameters, or add them query parameters can optional.
e.g. http://example.com/test/gettest?a=0&b=&c=1
public ienumerable<string> gettest(int32 idtest) { var querypairs = request.getquerynamevaluepairs(); dosomething(querypairs); ... }
Comments
Post a Comment