qtime67
qtime67

Reputation: 317

NancyFX: how to get posted form value?

I am sending a form post into NancyFX via an Ajax post. In debug, I can see that the data is there. (Request.Form.Keys.Count = 1 and Value = 1)

In debug I can see the key name, and the value.

When I try to access however using the notation indicated in documentation, I get null...

string Myvalue = Request.Form.MyData  // is null
var Myvalue = Request.Form["MyData"]  // is also null

Yet, I can see the name in Request.Form.Keys and the value in Request.Form.Values

I'm sure its something stupid - any ideas?

-- edit - here is ajax code --

 $.ajax({
    type: 'POST',
    url: "/ABC",
    **contentType : 'application/x-www-form-urlencoded; charset=UTF-8',**
    data: { FVSServer: $("#txtSomeValue").val()},
    async: false,
    success: function (results) {
    alert(results);
   }
  });

NB: strangely, even though its default, the contentType line above was required! ... many thanks!

Upvotes: 4

Views: 2298

Answers (1)

TheCodeJunkie
TheCodeJunkie

Reputation: 9616

Make sure you are posting with the correct content-type header. It needs to be application/x-www-form-urlencoded or it is not form data in the world of HTTP

Upvotes: 4

Related Questions