Web API 2 DataMember naming not working in FromUri parameters

随声附和 提交于 2021-02-11 08:55:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!