NancyFX: how to get posted form value?

c#, nancy

Solution

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

Problem

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!

Original source