简体   繁体   English

NancyFX:如何获得发布的表单价值?

[英]NancyFX: how to get posted form value?

I am sending a form post into NancyFX via an Ajax post. 我通过Ajax帖子向NancyFX发送了一个表单帖子。 In debug, I can see that the data is there. 在调试中,我可以看到数据存在。 ( Request.Form.Keys.Count = 1 and Value = 1 ) Request.Form.Keys.Count = 1Value = 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... 当我尝试使用文档中指示的符号访问时,我得到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 不过,我可以看到在名称Request.Form.Keys和值Request.Form.Values

I'm sure its something stupid - any ideas? 我确定它有点愚蠢 - 任何想法?

-- edit - here is ajax code -- - 编辑 - 这里是ajax代码 -

 $.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! 注意:奇怪的是,即使是默认值,上面的contentType行也是必需的! ... many thanks! ... 非常感谢!

Make sure you are posting with the correct content-type header. 确保使用正确的content-type标题发布。 It needs to be application/x-www-form-urlencoded or it is not form data in the world of HTTP 它需要是application/x-www-form-urlencoded或者它不是HTTP世界中的表单数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM