问题
I'm having issues with DataMember-naming in UriParameters.
[DataContract]
public class testobj
{
[DataMember(Name = "Test")]
public string a {get; set; }
[DataMember(Name = "Test1")]
public string b {get; set; }
}
Then i have my controller:
public IHttpActionResult test([FromUri] testobj testparams)
{
return testparams;
}
In the response i get Test
and Test1
, that's correct. However i have to use a
and b
in the uriParameters, why can't i use Test and Test1 there?
How can i fix this?
回答1:
You cannot pass an object type in the Query String, You have to pass it in the HTTP Packets Body, and use [FromBody] in your Controller methods Parameter.
here's a Stackoverflow link explaining more, ASP.NET Web APi - Passing an object as parameter
Thank You, Bhadhri
来源:https://stackoverflow.com/questions/41613159/web-api-2-datamember-naming-not-working-in-fromuri-parameters