c# - Is it possible to use a dash character in variable name .net Web API? -
the request sms api delivery report information sms.
one of variable posted api this: ?err-code=0. possible in .net web api solution or should use language?
web api method:
public httpresponsemessage get([fromuri]testmodel testingdetials) { return request.createresponse(system.net.httpstatuscode.ok); }
model
public class testmodel { public string foo { get; set; } public string err_code { get;set; } }
i tried various solution found on website none of them work adding [jsonproperty] , [datamember] err_code property.
you can use [jsonproperty(propertyname = "err-code")]
provided request being received json. because jsonproperty part of newtonsoft json serializer library web api uses deserialize json. if request not json, library not used in pipeline.
as mentioned can use httpcontext. if remember correctly model binding in mvc converts '-' '_' wrong. regardless continue using typed models, recommend, use model binding. writing custom mapping between http context , model. expand usual 1 , map "err-code" property called errcode automatically writing convention based one. here example, scroll bit: http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api happy coding! (through provide complete answer sake of...well... having complete answer)
Comments
Post a Comment