我正在通过 Ajax 帖子向 NancyFX 发送表单帖子。在调试中,我可以看到数据在那里。 (Request.Form.Keys.Count = 1
和 Value = 1
)
在调试中我可以看到键名和值。
当我尝试访问但是使用文档中指示的符号时,我得到 null...
string Myvalue = Request.Form.MyData // is null
var Myvalue = Request.Form["MyData"] // is also null
然而,我可以在 Request.Form.Keys
中看到名称,在 Request.Form.Values
中看到值
我确定这很愚蠢 - 有什么想法吗?
-- 编辑 - 这是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);
}
});
注意:奇怪的是,尽管它是默认的,但上面的 contentType 行是必需的! ...非常感谢!
最佳答案
确保您使用正确的 content-type
标题发帖。它需要是 application/x-www-form-urlencoded
否则它不是 HTTP 世界中的表单数据
关于c# - 南希FX : how to get posted form value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20202075/