0

I don't know its a stupid question or not ,for a clarification i am asking here. Please advice on the following situation.

I came up with a situation, that [FromBody] attribute can be specified to decorate a parameter inside the function and get the complex/simple data from the client. I do accepted it in both the ways and processed .

Is there any way that , i don't want to specify as a parameter in my POST function , and still be able to the body content in server side ?

 public HttpResponseMessage GetDetails([FromUri]int id)
 Var BodyJsonString =   // I need to get the body string inside my function, 
 but not specify in parameter list.
 // Later i map the JsoNString to class and parse it/.

Also i want to make the BODY is mandatory while calling my POST API. Tried [Required] inside the function parameter , but its for my above listed case.

jidh
  • 172
  • 1
  • 6
  • 22
  • Why are you using `[FromUri]` in your question but it appears to be about `[FromBody]` (and omitting it) – Mark C. Apr 24 '17 at 12:19
  • Mark, simple parameter like id i may pass [FromUri], its optional for me, what is mandatory is need to get body inside the GetDetails(), without specifying in parameter list, i am not sure even its a best practice or not. – jidh Apr 24 '17 at 12:29
  • You should use [FromUri] in case you want to send an object in the url (in case of a GET). You're obviously using a POST here. Have a quick look at https://damienbod.com/2014/08/22/web-api-2-exploring-parameter-binding/ . – Wouter van Vegchel Apr 24 '17 at 12:42

0 Answers0