1

当我使用 Json 发布 DateTime 时,出现以下错误:错误 500 无法将“System.DateTime”类型的对象转换为“System.Array”类型。

我不明白为什么!你能帮我吗 ?

标头发送如下所示:

{"MyDate":"2012-12-31T23:00:00.000Z","Param1":"aaaa","IdItem":123}

我的视图模型:

 public class MyViewModel
 {
public DateTime MyDate { get; set; }
public string Param1 {get;set;}
public Int32? IdItem { get; set; }
 }

我的控制器:

[HttpPost]
    public void Saisie(MyViewModel model)
    { ... }

我的 Javascript 代码:

$.ajax({
        url: url,
        type: 'post',
        dataType: 'json',
        data : JSON.stringify(model),
        contentType: 'application/json',
success : function() {...}
})
4

2 回答 2

2

使用 数据:$(form).serialize()而不是 数据:JSON.stringify(model)

于 2013-01-07T10:04:25.337 回答
0

我发现了我的问题,在我的视图模型中:

public class MyViewModel
{
[MaxLength(10)]
public DateTime MyDate { get; set; }
}

MaxLength 属性导致错误

于 2013-01-15T16:22:54.737 回答