有没有办法在页面加载时设置模型值。因为我需要它来填充模型值的模式。我尝试了一个document.ready ajax调用来获取模型,但它告诉我模型在ajax调用之前没有任何值。
这里是代码,您可以看到我如何尝试填充模式,但它不会遇到函数
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")"> </script>
<script src="@Url.Content("~/Scripts/kendo/kendo.all.min.js")"></script>
<script>
$(document).ready(function () {
$.ajax({
url: '/Team/Calendar/PopulateCalendar/',
type: "POST",
data: $(this).serialize(),
});
});
$(function () {
$("#scheduler").kendoScheduler({
date: new Date("2013/6/13"),
startTime: new Date("2013/6/13 07:00 AM"),
height: 600,
views: [
"day",
{ type: "week", selected: true },
"month",
"agenda"
],
timezone: "Etc/UTC",
dataSource: {
batch: true,
transport: {
read: {
url: "/Team/Calendar/PopulateCalendar/",
dataType: "json"
},
update: {
url: "http://demos.kendoui.com/service/tasks/update",
dataType: "jsonp"
},
create: {
url: "http://demos.kendoui.com/service/tasks/create",
dataType: "jsonp"
},
destroy: {
url: "http://demos.kendoui.com/service/tasks/destroy",
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "taskId",
fields: {
taskId: { from: "@Model.CalendarItems.Select(calendar=> calendar.TaskId)", type: "number" },
title: { from: "@Model.CalendarItems.Select(calendar=> calendar.Title)", defaultValue: "No title", validation: { required: true } },
start: { type: "date", from: "@Model.CalendarItems.Select(calendar => calendar.Start)" },
end: { type: "date", from: "@Model.CalendarItems.Select(calendar => calendar.End)" },
startTimezone: { from: "@Model.CalendarItems.Select(calendar => calendar.StartTimezone)" },
endTimezone: { from: "@Model.CalendarItems.Select(calendar => calendar.EndTimezone)" },
description: { from: "@Model.CalendarItems.Select(calendar => calendar.Description)" },
recurrenceId: { from: "@Model.CalendarItems.Select(calendar => calendar.RecurrenceId)" },
recurrenceRule: { from: "@Model.CalendarItems.Select(calendar => calendar.RecurrenceRule)" },
recurrenceException: { from: "@Model.CalendarItems.Select(calendar => calendar.RecurrenceException)" },
ownerId: { from: "OwnerID", defaultValue: 1 },
isAllDay: { type: "boolean", from: "@Model.CalendarItems.Select(calendar => calendar.IsAllDay)" }
}
}
},
filter: {
logic: "or",
filters: [
{ field: "ownerId", operator: "eq", value: 1 },
{ field: "ownerId", operator: "eq", value: 2 }
]
}
},
resources: [
{
field: "ownerId",
title: "Owner",
dataSource: [
{ text: "Alex", value: 1, color: "#f8a398" },
{ text: "Bob", value: 2, color: "#51a0ed" },
{ text: "Charlie", value: 3, color: "#56ca85" }
]
}
]
});
答案 0 :(得分:0)
我认为你正在使用带有Razor的ASPNET MVC,你应该可以通过Scriplet将你的模型设置为javascript。