将Kendo UI与MVC3结合使用。
使用开发人员工具上的网络选项卡,我可以看到正在发送所有正确的数据,但是当我将鼠标悬停在进入控制器方法的模型参数上时,日期都是1/1/0001。以下是一些数据:
来自网络请求标签的标题信息(显示正确的数据将转到控制器:
Accept:application/json, text/javascript, */*; q=0.01
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Origin:http://localhost:47621
Referer:http://localhost:47621/NewOrder/Detail/18
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
CommentId:9
CommentText:blah blah random text.
IncidentId:7
ModifiedBy:admin
ModifiedDate:Thu Jun 06 2013 08:15:08 GMT-0700 (Pacific Daylight Time)
CreatedBy:admin
CreatedDate:Thu Jun 06 2013 08:15:08 GMT-0700 (Pacific Daylight Time)
剑道代码:
var IncId = $("#IncidentId").val();
var ds_CommentsGrid = new kendo.data.DataSource({
transport: {
read : {
url : '@Url.Action("JsonGetComments", "TrespassOrder")/' + IncId,
dataType: 'json',
type : "POST"
},
update : {
url : '@Url.Action("JsonEditComment", "TrespassOrder")',
dataType: 'json',
type : "POST"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
var values = {};
values["CommentId"] = options.models[0].CommentId;
values["CommentText"] = options.models[0].CommentText;
values["IncidentId"] = options.models[0].IncidentId;
values["ModifiedBy"] = options.models[0].ModifiedBy;
values["ModifiedDate"] = options.models[0].ModifiedDate;
values["CreatedBy"] = options.models[0].CreatedBy;
values["CreatedDate"] = options.models[0].CreatedDate;
return values;
}
}
},
batch : true,
schema : {
model: {
id : "CommentId",
fields: {
CommentId : { editable: false },
CommentText : { editable: true },
CreatedDate : { editable: false, type: "date"},
ModifiedDate: { editable: false, type: "date" },
CreatedBy : { editable: false },
ModifiedBy : { editable: false }
}
}
},
pageSize : 5
});
$(document).ready(function () {
$("#Comment-List").kendoGrid({
dataSource: ds_CommentsGrid,
sortable : true,
filterable: { extra: false, operators: {
string: { startswith: "Starts with", eq: "Is equal to" }
}
},
pageable : true,
columns : [
{ field: "CommentText", title: "Comment", width: 300, filterable: false },
{ field: "CreatedBy", title: "Author", filterable: false },
{ field: "CreatedDate", title: "Original Date", format: "{0:g}", filterable: { ui: "datetimepicker" } },
{ field: "ModifiedBy", title: "Edited By", filterable: false },
{ field: "ModifiedDate", title: "Editted On", format: "{0:g}", filterable: { ui: "datetimepicker" } },
{ command: ["edit"], title: "Actions" }
],
editable : "popup"
});
});
我想知道请求标题中提到的内容类型,它是否正确?
答案 0 :(得分:0)
尝试以json发送响应:
update: {
url : '@Url.Action("JsonEditComment", "TrespassOrder")',
dataType: 'json',
type : "POST",
contentType: "application/json"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
var values = {};
values["CommentId"] = options.models[0].CommentId;
values["CommentText"] = options.models[0].CommentText;
values["IncidentId"] = options.models[0].IncidentId;
values["ModifiedBy"] = options.models[0].ModifiedBy;
values["ModifiedDate"] = options.models[0].ModifiedDate;
values["CreatedBy"] = options.models[0].CreatedBy;
values["CreatedDate"] = options.models[0].CreatedDate;
return JSON.stringify(values);
}
}
ASP.NET MVC无法解析JavaScript Date对象的字符串表示形式。但是,当它被序列化为JSON时,它可以解析它。