Is it possible to create a parameter binding on both FromURI and FromBody?

前端 未结 1 375
孤独总比滥情好
孤独总比滥情好 2021-01-28 12:34

I looked up up the documentation for ASP.NET Web API parameter binding, they seem to have either fromURI and fromBody only. Is it possible to do both?

Here is some backg

1条回答
  •  醉梦人生
    2021-01-28 13:09

    If I understand correctly you're trying to use both the Post data from the body and some parameters from the URI. The example below should capture your "source=a" value from the queryString.

        [Route("incoming")]
        [HttpPost]
        public IHttpActionResult Test([FromBody] string data, string source)
        {
            //Do something
    
            return Ok("my return value");
        }
    

    Or you could use as below if you formatted your route as .../api/incoming/source/A.

        [Route("incoming/{source:string}")]
        [HttpPost]
        public IHttpActionResult Test([FromBody] string data, string source)
        {
            //Do something
    
            return Ok("my return value");
        }
    

    0 讨论(0)
提交回复
热议问题