我试图将以下数据从我的视图传递给控制器。
已编辑
<script type="text/javascript">
var pathname = 'http://' + window.location.host;
var Student = [
{ Name: "Vijay", ID: 1, DOB: "2010-12-09T08:00:00.000Z" },
{ Name: "Anand", ID: 2, DOB: "2010-12-09T08:00:00.000Z" }
];
$.ajax({
url: pathname + "/Home/UpadetStu",
type: "POST",
dataType: "json",
data: JSON.stringify(Student),
contentType: "application/json; charset=utf-8",
success: function (result) { },
failure: function (r, e, s) { alert(e); }
});
</script>
[ObjectFilter(Param = "stuData", RootType = typeof(Stu[]))]
public JsonResult UpadetStu(Stu[] stuData)
{
return this.Json(new { success = true });
}
[DataContract]
public class Stu
{
[DataMember]
public string Name { get; set; }
[DataMember]
public int ID { get; set; }
[DataMember]
public DateTime? DOB { get; set; }
}
但是在控制器中 Name 和 ID 为空,DOB 的默认日期时间,我发现传递日期时间有问题。有没有更好的方法将日期时间从视图传递到控制器?我错过任何解析吗?