Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Nancy model binding不适用于Chrome,即_C#_Javascript_Ajax_Nancy - Fatal编程技术网

C# Nancy model binding不适用于Chrome,即

C# Nancy model binding不适用于Chrome,即,c#,javascript,ajax,nancy,C#,Javascript,Ajax,Nancy,我在我的一个应用程序中遇到了这个问题,并将其剥离,并建立了一个小的测试环境,在这个环境中问题仍然存在 我正在发布以下对象(JSON) 使用以下ajax调用 self.save = function (item, url, success) { $.ajax({ type: "post", data: JSON.stringify(item), contentType: "application/json, charset=utf-8",

我在我的一个应用程序中遇到了这个问题,并将其剥离,并建立了一个小的测试环境,在这个环境中问题仍然存在

我正在发布以下对象(JSON)

使用以下ajax调用

self.save = function (item, url, success) {
    $.ajax({
        type: "post",
        data: JSON.stringify(item),
        contentType: "application/json, charset=utf-8",
        traditional: true,
        datatype: "json",
        url: self.domain + url,
        success: success,
        error: self.error
    });
};
然后在服务器上用以下代码绑定数据

var Model = this.Bind<PropertyType>();
这在Firefox中工作得非常好。在Chrome和IE中,
模型
最终成为一个具有所有空值的
事件
对象。据我所知(通过使用Fiddler),所有浏览器之间的post请求完全相同。我也在其他机器上进行了测试,排除了我的机器和/或浏览器的问题


有什么想法吗?我不明白浏览器如何影响Nancy model binding…

简单的答案是您的内容类型无效。不存在
应用程序/json,charset=utf-8
内容类型,不管人们会告诉你什么。尽管
charset
是内容类型的有效、可选的扩展,但它不适用于
application/json

您可以在这里的
6 IANA注意事项

JSON文本的MIME媒体类型为application/JSON

类型名称:应用程序

子类型名称:json

所需参数:不适用

可选参数:不适用

还有关于编码的附加说明

编码注意事项:UTF-8时为8位;如果是UTF-16或UTF-32,则为二进制

 JSON may be represented using UTF-8, UTF-16, or UTF-32.  When JSON
 is written in UTF-8, JSON is 8bit compatible.  When JSON is
 written in UTF-16 or UTF-32, the binary content-transfer-encoding
 must be used.
简而言之,JSON已经隐式地成为了utf-8。事实上,在第3节下。编码它表示

JSON文本应采用Unicode编码。默认编码是UTF-8

发送
application/json
,您应该设置为go


希望这有帮助:-)

哇,我真不敢相信是这样。谢谢你的帮助。
public class Event
{
    public string EventName { get; set; }
    public int Tickets { get; set; }
    public Venue Venue { get; set; }
    public string TicketsLocation { get; set; }
    public DateTime Date { get; set; }
    public List<EventRequest> Requests { get; set; }
}
 JSON may be represented using UTF-8, UTF-16, or UTF-32.  When JSON
 is written in UTF-8, JSON is 8bit compatible.  When JSON is
 written in UTF-16 or UTF-32, the binary content-transfer-encoding
 must be used.