ポップアップ作成で剣道グリッドを使用します。データソースを使用したコードは次のとおりです。
var PersId = $("#PersonId").val();
var ds_CommentsGrid = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Action("JsonGetComments", "TrespassOrder")/' + PersId,
dataType: 'json',
},
update: {
url: '@Url.Action("JsonEditComment", "TrespassOrder")',
dataType: 'json',
type: "POST"
},
create: {
url: '@Url.Action("JsonAddComment", "TrespassOrder")',
dataType: 'json',
type: "POST"
//contentType: 'application/json; charset=UTF-8',
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
var values = {};
values["CommentText"] = options.models[0].CommentText;
values["ModifiedBy"] = options.models[0].ModifiedBy;
values["ModifiedDate"] = options.models[0].ModifiedDate;
values["CreatedBy"] = options.models[0].CreatedBy;
values["CreatedDate"] = options.models[0].CreatedDate;
values["PersonId"] = options.models[0].PersonId;
return values;
}
}
},
batch: true,
schema: {
model: {
id: "CommentId",
fields: {
CommentText: { editable: true },
CreatedDate: { editable: false , type: "date"},
ModifiedDate: { editable: false , type: "date" },
CreatedBy: { editable: false },
ModifiedBy: { editable: false },
PersonId: { 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: true
}, {
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",
toolbar: [{ name: "create", text: "Add New Comment" }]
});
});
2 つの問題があります。 1. Create で PersonId が送信されていません。2. 日付は、最終的に MVC コントローラーに null (1/1/0001) として到達する形式で送信されています。
コントローラーに送信される内容は次のとおりです。
Request URL:http://localhost:47621/TrespassOrder/JsonAddComment
Request Headersview source
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/Person/Detail/18
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
CommentText:Blah blah, I am a comment.
ModifiedBy:
ModifiedDate:Fri Jun 14 2013 12:12:46 GMT-0700 (Pacific Daylight Time)
CreatedBy:
CreatedDate:Fri Jun 14 2013 12:12:46 GMT-0700 (Pacific Daylight Time)
PersonId:
PersonId が空であることに注意してください。
トランスポート内の create でコメントアウトされた contentType に注意してください。json コンテンツ タイプを使用してみましたが、「CommentText は無効な JSON プリミティブです」というエラーが返されました。
では、コントローラーに表示されるように日付をフォーマットする方法と、送信されるデータに外部キー (PersonId) を添付する方法を教えてください。