Kendo Grid 인라인 편집 CRUD를 구현하는 중에 오류가 발생했습니다. 새 레코드를 추가하고 업데이트하면 오류가있는 응답 코드 500이 표시됩니다."잘못된 JSON 프리미티브 : 모델"오류 컨트롤러에 모델을 전달하는 동안 Kendo Grid 데이터 소스에서
나는이 문제가 parameterMap
에서 발생한다고 생각합니다. Kendo의 컨트롤러에 모델을 전달하는 올바른 방법은 무엇입니까?
Invalid JSON primitive: models.
모델은 무엇입니까?
소스 코드 :
$(document).ready(function() {
var baseUrl = "/SomeUrl",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: baseUrl + "/GetAccolades?profileId=" + @profileId,
type: "GET",
dataType: "json"
},
create: {
url: baseUrl + "/AddAccolade",
type: "POST",
dataType: "json",
contentType: "application/json",
},
update: {
url: baseUrl + "/UpdateAccolade",
type: "PUT",
dataType: "json",
contentType: "application/json",
},
delete: {
url: baseUrl + "/DeleteAccolade",
type: "DELETE",
dataType: "json"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
alert(kendo.stringify(options.models));
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
schema: {
model: {
id: "ProfileAccoladeID",
fields: {
ProfileAccoladeID: { editable: false, nullable: false },
ProfileID: { editable: false, nullable: false, defaultValue: @profileId },
Years: { type: "string" },
Name: { type: "string" },
Level: { type: "string" },
Event: { type: "string" },
}
}
}
});
$("#accolades-grid").kendoGrid({
dataSource: dataSource,
pageable: false,
height: 550,
toolbar: ["create"],
columns: [
{ field: "Years", width: "150px" },
{ field: "Name", title: "Name", width: "150px" },
{ field: "Level", title: "Level", width: "150px" },
{ field: "Event", title: "Event", width: "450px" },
{ command: ["edit", "destroy"], title: " ", width: "250px" }],
editable: "inline"
});
});
</script>
컨트롤러 방법 :
[HttpPost]
public JsonResult AddAccolade(ProfileAccolade accolade)
{
using (var db = new XXXEntities())
{
if (accolade != null)
{
var newAccolade = new ProfileAccolade()
{
ProfileID = accolade.ProfileID,
Years = accolade.Years,
Name = accolade.Name,
Level = accolade.Level,
Event = accolade.Event
};
db.ProfileAccolades.Add(newAccolade);
db.SaveChanges();
return Json(new { Success = true });
}
else
{
return Json(new { Success = false, Message = "Error occured" });
}
}
}
가 어떻게이 오류를 수정합니까?
업데이트 : 오류 Invalid JSON primitive: models.
contentType: "application/json",
을 제거함으로써
가 없어. 그러나 컨트롤러는 모델을 얻지 못합니다.
해결 방법이 있습니까?
'alert (kendo.stringify (options.models)) '에서 어떤 종류의 JSON 문자열 결과를 얻었습니까? 일반적으로이 문제는 JSON 문자열 형식 대신 URL 인코딩 된 매개 변수가있는 메서드를 호출 한 후에 발생합니다. –
당신은 보셨나요? https://stackoverflow.com/questions/18695302/kendo-datasource-parameter-map – jwatts1980
@Tetsuya Yamamoto 잘 형식화 된 JSON 문자열이 있습니다. –