0

So I know that this works:

[HttpPost]
public string functionthatiuse()
{
    string id = "";//does nothing
    return relevantinfo;
}

Then I use this Chrome POST extension shown below and I have a break point in the function which is how I know it reaches it. It's literally an empty post request basically.

dsdf

But when I try to post with parameters I'm having trouble. Ideally I want to do something like this:

[HttpPost]
public string functionthatiuse(string idx)
{
    string id = ""; //does nothing and is different from idx
    return relevantData;
}

but when I try to use it I get an error back. I'm pretty sure it's because I'm not formatting the content body correctly and I've tried putting other stuff in the content body, but nothing has really worked. Does anyone know how I can send POST parameters to this function using this extension? The format of what I'm doing in code should be basically the same (part of a requirement).

Edit:

Here's a picture of the error:

enter image description here

GDub
  • 544
  • 2
  • 7
  • 15
  • What error? What are you sending in the failing request? – David Jun 19 '15 at 15:27
  • At what point does the error come? is it before `string id = "";` – laskdjf Jun 19 '15 at 15:33
  • I actually have no clue what I should be sending. So I've tried what you see above. I've tried [idx=hello], [idx="hello"],[randomtext]. So that's basically the issue. I'm not sure – GDub Jun 19 '15 at 15:33
  • There's no error in the code. It's in the http post request. It doesn't even reach the code. – GDub Jun 19 '15 at 15:34
  • Can you put the code of the form that is supposed to call this Post method. – laskdjf Jun 19 '15 at 15:36
  • I'm not sure if that is publicly available or not. Though I can tell you the Chrome extension is called "Chrome Poster" – GDub Jun 19 '15 at 15:38
  • The code is in this repository on github. https://github.com/dengzhp/chrome-poster – GDub Jun 19 '15 at 15:40
  • Not the code for Chrome Poster. Your code, on your website what do you click that is supposed to call `functionthatiuse()`. Can you put the html. – laskdjf Jun 19 '15 at 15:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/81016/discussion-between-user3869404-and-fahad-jameel). – GDub Jun 19 '15 at 16:12

1 Answers1

0

According to microsoft here: http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api

You have to add "[FromBody]" in the parameter list. You can only have one of these types of parameters.

Also in the chrome post extension under headers you need to enter:

Name: Content-Type Value: application/json

GDub
  • 544
  • 2
  • 7
  • 15