Kendo Grid with 팝업 작성 Create를 사용하십시오. 1 PersonId은 작성과 함께 전송되지 않는 :Kendo Ui 편집기가 작성시 FK를 보내지 않음
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 문제가 있습니다 : 여기에 데이터 소스와 코드입니다. 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가 비어 있습니다.
전송 내에서 작성한 주석 처리 된 contentType에 유의하십시오. json 콘텐츠 유형을 사용하려고했지만 'CommentText가 잘못된 JSON 프리미티브입니다'라는 오류가 반환되었습니다.
그래서 날짜가 컨트롤러에 나타나도록하려면 어떻게해야합니까? 전송되는 데이터 (PersonId) 키?
이 값을 기본값으로하지 않은, 편집 가능한 설정되지 않고column
가 없습니다
@OnaBai을 - 덕분에 내가 가진 personid 고정 : PersonId : {DEFAULTVALUE : PersId를}. 어떤 아이디어가 날짜 형식으로 진행됩니까? – BattlFrog